def test_intersect(self): p = Polygon(self.l1, self.ext1) p2 = Polygon(self.l1, self.ext2) p3 = Polygon(self.l1, self.ext3) d = distance(p, p2) self.assertLessEqual(d, 0) d = distance(p2, p3) self.assertLessEqual(d, 0) d1 = distance(p, p3) self.assertGreater(d1, 0)
def test_inner_ring(self): ext = [Point2(0, 0), Point2(10, 0), Point2(10, 10), Point2(0, 10)] inner = [Point2(3, 3), Point2(7, 3), Point2(7, 7), Point2(3, 7)] inner2 = [Point2(4, 4), Point2(6, 4), Point2(6, 6), Point2(4, 6)] outer_ring = Polygon(self.l1, ext, [inner]) inner_ring = Polygon(self.l1, inner2) self.assertAlmostEqual(distance(outer_ring, inner_ring), 1) outer_ring.get_tris_repr() inner_ring.get_tris_repr()
def test_inner_ring(self): ext = [Point2(0,0), Point2(10, 0), Point2(10, 10), Point2(0, 10)] inner = [Point2(3,3), Point2(7, 3), Point2(7, 7), Point2(3, 7)] inner2 = [Point2(4,4), Point2(6, 4), Point2(6, 6), Point2(4, 6)] outer_ring = Polygon(self.l1, ext, [inner]) inner_ring = Polygon(self.l1, inner2) self.assertAlmostEqual(distance(outer_ring, inner_ring), 1) outer_ring.get_tris_repr() inner_ring.get_tris_repr()
def intersect_with(self, a, b): """ returns all geoms from list b that intersect with a :param a: :param b: :return: """ bbox_items = self.__index.intersect(a.bbox) pruned_list = b.intersection(bbox_items) res = [] for i in pruned_list: if distance(a, i) <= 0: res.append(i) return res
def query(self, geom, bbox_prune = False): """ :param geom: object to query :param distance: if d is None, find nearest object (or all touching objects). If d is a number, those nearer than d :return: list of artwork objects """ assert bbox_prune if bbox_prune: ilist = self.__index.intersect(geom.bbox) ilist = [i for i in ilist if i.ISC != IntersectionClass.NONE] return sorted([(distance(geom, other), other) for other in ilist], key=operator.itemgetter(0)) bbox = geom.bbox results = [] if isinstance(geom, Via): # Build structures used to determine if artwork is on same layer vps_ok = {} my_layerset = set(id(i) for i in geom.viapair.all_layers) for v in self.__project.stackup.via_pairs: v_layerset = set(id(i) for i in v.all_layers) vps_ok[id(v)] = len(v_layerset.intersection(my_layerset)) for other in self.__vias: if not vps_ok[id(other.viapair)]: continue if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_via_via(geom, other), other )) for other in self.__traces: if id(other.layer) not in my_layerset: continue if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_via_trace(geom, other), other )) for other in self.__all_pads: if other.is_through() or other.layer in geom.viapair.all_layers: if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_via_pad(geom, other), other )) elif isinstance(geom, Trace): for other in self.__traces: if other.layer is not geom.layer: continue if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_trace_trace(geom, other), other )) # Build lookup to check viapair vps_ok = {} for v in self.__project.stackup.via_pairs: v_layerset = set(id(i) for i in v.all_layers) vps_ok[id(v)] = id(geom.layer) in v_layerset for other in self.__vias: if not vps_ok[id(other.viapair)]: continue if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_via_trace(other, geom), other )) for other in self.__all_pads: if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_trace_pad(geom, other), other )) elif isinstance(geom, Pad): # TODO: More opts here, can exclude some pads based on TH for other in self.__vias: if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_via_pad(other, geom), other )) for other in self.__traces: if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_trace_pad(other, geom), other )) for cmp in self.__components: if bbox_prune and not bbox.intersects(cmp.bbox): continue for other in cmp.get_pads(): if bbox_prune and not bbox.intersects(other.bbox): continue results.append(( dist_pad_pad(geom, other), other )) else: raise NotImplementedError() return sorted(results, key=operator.itemgetter(0))
def query(self, geom, bbox_prune=False): """ :param geom: object to query :param distance: if d is None, find nearest object (or all touching objects). If d is a number, those nearer than d :return: list of artwork objects """ assert bbox_prune if bbox_prune: ilist = self.__index.intersect(geom.bbox) ilist = [i for i in ilist if i.ISC != IntersectionClass.NONE] return sorted([(distance(geom, other), other) for other in ilist], key=operator.itemgetter(0)) bbox = geom.bbox results = [] if isinstance(geom, Via): # Build structures used to determine if artwork is on same layer vps_ok = {} my_layerset = set(id(i) for i in geom.viapair.all_layers) for v in self.__project.stackup.via_pairs: v_layerset = set(id(i) for i in v.all_layers) vps_ok[id(v)] = len(v_layerset.intersection(my_layerset)) for other in self.__vias: if not vps_ok[id(other.viapair)]: continue if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_via_via(geom, other), other)) for other in self.__traces: if id(other.layer) not in my_layerset: continue if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_via_trace(geom, other), other)) for other in self.__all_pads: if other.is_through( ) or other.layer in geom.viapair.all_layers: if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_via_pad(geom, other), other)) elif isinstance(geom, Trace): for other in self.__traces: if other.layer is not geom.layer: continue if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_trace_trace(geom, other), other)) # Build lookup to check viapair vps_ok = {} for v in self.__project.stackup.via_pairs: v_layerset = set(id(i) for i in v.all_layers) vps_ok[id(v)] = id(geom.layer) in v_layerset for other in self.__vias: if not vps_ok[id(other.viapair)]: continue if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_via_trace(other, geom), other)) for other in self.__all_pads: if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_trace_pad(geom, other), other)) elif isinstance(geom, Pad): # TODO: More opts here, can exclude some pads based on TH for other in self.__vias: if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_via_pad(other, geom), other)) for other in self.__traces: if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_trace_pad(other, geom), other)) for cmp in self.__components: if bbox_prune and not bbox.intersects(cmp.bbox): continue for other in cmp.get_pads(): if bbox_prune and not bbox.intersects(other.bbox): continue results.append((dist_pad_pad(geom, other), other)) else: raise NotImplementedError() return sorted(results, key=operator.itemgetter(0))
def test_separate_layers(self): p = Polygon(self.l1, self.ext1) p2 = Polygon(self.l2, self.ext2) self.assertGreater(distance(p, p2), 0)
def query(self, geom: QueryableGeom, bbox_prune: bool = False) -> List[Tuple[float, Geom]]: """ :param geom: object to query :return: list of artwork objects """ assert bbox_prune if bbox_prune: ilist = self.__index.intersect(geom.bbox) ilist = [i for i in ilist if i.ISC != IntersectionClass.NONE] return sorted([(distance(geom, other), other) for other in ilist], key=operator.itemgetter(0)) bbox = geom.bbox # TODO refine geom type results: List[Tuple[float, Any]] = [] if isinstance(geom, Via): # Build structures used to determine if artwork is on same layer vps_ok = {} my_layerset = set(id(i) for i in geom.viapair.all_layers) for v in self.__project.stackup.via_pairs: v_layerset = set(id(i) for i in v.all_layers) vps_ok[id(v)] = len(v_layerset.intersection(my_layerset)) for other_via in self.__vias: if not vps_ok[id(other_via.viapair)]: continue if bbox_prune and not bbox.intersects(other_via.bbox): continue results.append((dist_via_via(geom, other_via), other_via)) for other_trace in self.__traces: if id(other_trace.layer) not in my_layerset: continue if bbox_prune and not bbox.intersects(other_trace.bbox): continue results.append((dist_via_trace(geom, other_trace), other_trace)) for other_pad in self.__all_pads: if other_pad.is_through( ) or other_pad.layer in geom.viapair.all_layers: if bbox_prune and not bbox.intersects(other_pad.bbox): continue results.append((dist_via_pad(geom, other_pad), other_pad)) elif isinstance(geom, Trace): for other_trace in self.__traces: if other_trace.layer is not geom.layer: continue if bbox_prune and not bbox.intersects(other_trace.bbox): continue results.append((dist_trace_trace(geom, other_trace), other_trace)) # Build lookup to check viapair vps_ok = {} for v in self.__project.stackup.via_pairs: v_layerset = set(id(i) for i in v.all_layers) vps_ok[id(v)] = id(geom.layer) in v_layerset for other_via in self.__vias: if not vps_ok[id(other_via.viapair)]: continue if bbox_prune and not bbox.intersects(other_via.bbox): continue results.append((dist_via_trace(other_via, geom), other_via)) for other_pad in self.__all_pads: if bbox_prune and not bbox.intersects(other_pad.bbox): continue results.append((dist_trace_pad(geom, other_pad), other_pad)) elif isinstance(geom, Pad): # TODO: More opts here, can exclude some pads based on TH for other_via in self.__vias: if bbox_prune and not bbox.intersects(other_via.bbox): continue results.append((dist_via_pad(other_via, geom), other_via)) for other_trace in self.__traces: if bbox_prune and not bbox.intersects(other_trace.bbox): continue results.append((dist_trace_pad(other_trace, geom), other_trace)) for cmp in self.__components: if bbox_prune and not bbox.intersects(cmp.bbox): continue for other_pad in cmp.get_pads(): if bbox_prune and not bbox.intersects(other_pad.bbox): continue results.append((dist_pad_pad(geom, other_pad), other_pad)) else: raise NotImplementedError() return sorted(results, key=operator.itemgetter(0))