Skip to content

Commit

Permalink
Fixes for islandHatcher
Browse files Browse the repository at this point in the history
Resolved a few issues with IslandHatcher failing on empty geometries or those with unclipped islands
  • Loading branch information
drlukeparry committed Aug 4, 2022
1 parent 02ccc1d commit f9ff55e
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions pyslm/hatching/islandHatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ def hatch(self, boundaryFeature) -> Layer:

curBoundary = self.offsetBoundary(boundaryFeature, offsetDelta)

if len(curBoundary) < 1:
# No internal regions to hatch
return layer

scanVectors = []

# Iterate through each closed polygon region in the slice. The currently individually sliced.
Expand Down Expand Up @@ -371,28 +375,35 @@ def hatch(self, boundaryFeature) -> Layer:
# ISSUE - the max coordinate id should be used to update this but it adds additional computiatonal complexity
idx += coords.shape[0] / 2

clippedCoords = np.vstack(clippedCoords)
unclippedCoords = np.vstack(unclippedCoords).reshape(-1,2,3)
if len(unclippedCoords) < 1:
unclippedCoords = np.array([]).reshape(-1,2,3)
else:
unclippedCoords = np.vstack(unclippedCoords).reshape(-1, 2, 3)

if len(clippedCoords) > 0:
clippedCoords = np.vstack(clippedCoords)

# Clip the hatches of the boundaries to fill to the boundary
clippedPaths = self.clipLines(curBoundary, clippedCoords)
clippedPaths = np.array(clippedPaths)

# Clip the hatches of the boundaries to fill to the boundary
clippedPaths = self.clipLines(curBoundary, clippedCoords)
clippedPaths = np.array(clippedPaths)
else:
clippedPaths = np.array([]).reshape(-1,2,3)

# Merge hatches from both groups together
hatches = np.vstack([clippedPaths, unclippedCoords])
clippedLines = self.clipperToHatchArray(hatches)

# Merge the lines together
if len(clippedPaths) > 0:
if len(clippedLines) > 0:

# Extract only x-y coordinates and sort based on the pseudo-order stored in the z component.
clippedLines = clippedLines[:, :, :3]
id = np.argsort(clippedLines[:, 0, 2])
clippedLines = clippedLines[id, :, :]

clippedLines = clippedLines[id, :, :]
scanVectors.append(clippedLines)


if len(clippedLines) > 0:
# Scan vectors have been created for the hatched region

Expand Down

0 comments on commit f9ff55e

Please sign in to comment.