Skip to content

Commit

Permalink
Add support for collections in closestIntersectionPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
SmittyHalibut committed May 9, 2023
1 parent f84d28c commit f58e29b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion kikit/panelize.py
Expand Up @@ -1338,7 +1338,7 @@ def makeVCuts(self, cuts, boundCurves=False, offset=fromMm(0)):
for cut in cuts:
if len(cut.simplify(SHP_EPSILON).coords) > 2 and not boundCurves:
raise RuntimeError("Cannot V-Cut a curve")
cut = cut.parallel_offset(offset, "left")
cut = cut.simplify(1).parallel_offset(offset, "left")
start = roundPoint(cut.coords[0])
end = roundPoint(cut.coords[-1])
if start.x == end.x or (abs(start.x - end.x) <= fromMm(0.5) and boundCurves):
Expand Down
18 changes: 10 additions & 8 deletions kikit/substrate.py
Expand Up @@ -424,14 +424,16 @@ def closestIntersectionPoint(origin, direction, outline, maxDistance):
plt.show()
raise NoIntersectionError(f"No intersection found within given distance", origin)
origin = Point(origin[0], origin[1])
if isinstance(inter, Point):
geoms = [inter]
elif isinstance(inter, LineString):
# When a linestring is an intersection, we know that the starting or
# ending points are the nearest one
geoms = [Point(inter.coords[0]), Point(inter.coords[-1])]
else:
geoms = inter.geoms
geoms = list()
for geom in listGeometries(inter):
if isinstance(geom, Point):
geoms.append(geom)
elif isinstance(geom, LineString):
# When a linestring is an intersection, we know that the starting or
# ending points are the nearest one
geoms.extend([Point(geom.coords[0]), Point(geom.coords[-1])])
else:
raise TypeError(f"intersection() returned an unsupported datatype: {geom.__class__.__name__}")
return min([(g, origin.distance(g)) for g in geoms], key=lambda t: t[1])[0]

def linestringToKicad(linestring):
Expand Down

0 comments on commit f58e29b

Please sign in to comment.