def plot_shape(ax, shape): for r in shape.generate_regions(): plot_region(ax, r) # make a fake region and plot it to keep axis equal br = shape.br + 1 r = Region(Point(-br, -br, -br), Point(br, br, br)) plot_region(ax, r)
def generate_regions(self, max_volume=32768): ''' * find all corners in y layer * for each cornerpoint that doesn't exist in layer above" * create regions by mirroring corner points about all 3 axis * apply limits * split * next y how to make this better: * work with even diameters ''' regions = [] last_corner_points = [] for y in range(self.br, -1, -1): corner_points = [] x_start = self.br for z in range(0, self.br + 1): for x in range(x_start, -1, -1): p = Point(x, y, z) if self.contains(p): if not self.contains(Point(x, y, z + 1)): corner_points.append(p) x_start = p.x # start at this x for next z break # next z # print("y: {}, n: {}, corners: {}".format(y, len(corner_points), # corner_points)) # mirror the point across all 3 axis to create a region for p in corner_points: plast = Point(p.x, p.y + 1, p.z) if plast not in last_corner_points: r = Region(p, Point(-p.x, -p.y, -p.z)) r.apply_limits(xmin=self.limits_min['x'], xmax=self.limits_max['x'], ymin=self.limits_min['y'], ymax=self.limits_max['y'], zmin=self.limits_min['z'], zmax=self.limits_max['z']) for sr in r.split(max_volume=max_volume): regions.append(sr) last_corner_points = corner_points return regions
def __init__(self, diameter, length, axis='z', origin=Point(0, 0, 0)): super(CylinderSolid, self).__init__(origin=origin) if axis not in ('x', 'y', 'z'): raise Exception("Invalid axis: {}".format(axis)) self.len = length self.d = diameter self.r = diameter / 2 self.br = max(self.len // 2, self.d // 2) self.axis = axis
def __init__(self, diameter, length, axis='z', origin=Point(0, 0, 0)): super(ArcTunnelSolid, self).__init__(diameter, length, axis=axis, origin=origin) if axis == 'y': raise Exception("Cannot do Arc Tunnel along 'y' axis.") self.limits_min['y'] = 0
def __init__(self, diameter, origin=Point(0, 0, 0)): super(SphereSolid, self).__init__(origin=origin) if diameter % 2 != 1: raise Exception("Cannot do even diameters: {}".format(diameter)) if diameter <= 1: raise Exception("Cannot do diameter <= 1") self.d = diameter self.r = self.d / 2 self.br = math.floor(self.r) # brick range
def __init__(self, origin=Point(0, 0, 0)): self.origin = origin self.br = None # this must be set in subclass (brick range) self.limits_min = {'x': None, 'y': None, 'z': None} self.limits_max = {'x': None, 'y': None, 'z': None}
def test_wrap(self): self.assertTrue(isinstance(Point.wrap((0, 0)), Point)) p = Point(3, 4) self.assertTrue(p is Point.wrap(p)) self.assertTrue(isinstance(Point.wrap([0, 0]), Point))
def test_distance_classmethod(self): a = Point(1, 1) b = Point(2, 2) d = Point.distance(a, b) self.assertAlmostEquals(1.4142135623730951, d)
def test_distance_instancemethod(self): d = Point(1, 1).distance(Point(2, 2)) self.assertAlmostEquals(1.4142135623730951, d)