Code speed up

This commit is contained in:
Lukas Klass 2020-05-06 10:13:00 +02:00
parent e4af7b8f23
commit c289cee9b5

View File

@ -88,44 +88,3 @@ def rasterizeCircle(n: int, radius: float, xc: float, yc: float):
# ax.add_artist(circle) # ax.add_artist(circle)
# plt.show() # plt.show()
return grid return grid
#
# import numpy as np
# import math
# import matplotlib.pyplot as plt
#
# n = 20 # Grid size, 4 times my visualized output in order to be able to truncate some circles
# radius = 0 # Radius
# xc = 9.5 # X center
# yc = 10.3 # Y center
# grid = np.zeros((n, n)) # Initialize an empty grid
# xc_pix = round(xc) # X center in pixel coordinates
# x_shift = xc_pix - xc # X shift of the circle center
# yc_pix = round(yc) # Y center in pixel coordinates
# y_shift = yc_pix - yc # Y shift of the circle center
# radius_pix = math.ceil(radius) + 1 # Length of the square containing the pixels to be checked
# r2 = radius ** 2 # square of the radius
#
# grid[xc_pix, yc_pix] = 1 # Set the center pixel by default
# # Iterate over all pixels in x direction
# for dx in np.arange(- radius_pix if xc_pix - radius_pix >= 0 else - xc_pix,
# radius_pix + 1 if grid.shape[0] > (xc_pix + radius_pix + 1) else grid.shape[0] - xc_pix):
# dx2 = (dx + x_shift) ** 2 # Square of the x-component of the current pixels radius
# # Square of the x-component of the neighbouring pixels radius
# dx_side2 = (dx + x_shift + (0.5 if dx < 0 else -0.5)) ** 2
# # Iterate over all pixels in y direction
# for dy in np.arange(- radius_pix if yc_pix - radius_pix >= 0 else - yc_pix,
# radius_pix + 1 if grid.shape[1] > (yc_pix + radius_pix + 1) else grid.shape[1] - yc_pix):
# dy2 = (dy + y_shift) ** 2 # Square of the y-component of the current pixels radius
# # Square of the y-component of the neighbouring pixels radius
# dy_side2 = (dy + y_shift + (0.5 if dy < 0 else -0.5)) ** 2
# if dx_side2 + dy2 <= r2 or dx2 + dy_side2 < r2:
# # A centerpoint between the current pixel and the two neighbouring pixels is within
# # the circle. Mark the current pixel as contained.
# grid[xc_pix + dx, yc_pix + dy] = 1
#
# fig, ax = plt.subplots()
# plt.imshow(grid.transpose())
# circle = plt.Circle((xc, yc), radius, color='r', fill=False)
# ax.add_artist(circle)
# plt.show()