def safeAddPoints(self, point1, point2): dist_prime = point_dist(point1, point2) if dist_prime < self.distance: self.clearAndAddPoints(point1, point2) self.setDistance(dist_prime) elif dist_prime == self.distance: self.addPoints(point1, point2)
def cyl_test(current_dim, point): x, y, z = point return dim == current_dim and \ base_y <= y <= base_y + height and \ point_dist((x,z), (base_x, base_z)) <= radius
def bounds_cube(dim, a, b): ranges = zip(a,b) # Ranges is a list of (a_coord, b_coord) for axis in ranges: axis = sorted(axis) def cube_test(current_dim, point): return current_dim == dim and all(lower < coord < upper for coord, (lower, upper) in zip(point, ranges)) return cube_test def bounds_cyl(dim, base, radius, height) # base is the point at the bottom middle of the cyl base_x, base_y, base_z = base def cyl_test(current_dim, point) x, y, z = point return dim == current_dim and min_height <= y <= max_height and point_dist((x,z), (base_x, base_z)) <= radius return cyl_test def bounds_union(*bounds_infos): def union_test(current_dim, point): return any(get_bounds_fn(*bounds_info)(current_dim, point) for bounds_info in bounds_infos) bounds_styles = {'cube': bounds_cube, 'cylinder': bounds_cyl} def get_bounds_fn(style, *args): fn = bounds_styles[style](*args) return fn # --- End bounds code ---