From de4e435d0cd8fa595cae13b5ff486e19736a301d Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Tue, 19 Nov 2024 18:50:40 +0100 Subject: [PATCH] Fix problem with extra line segments on multipoint intersections (#2640) --- .../io/gcode/toolpaths/LaserFillToolPath.java | 7 +++ .../toolpaths/LaserFillToolPathTest.java | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 ugs-platform/ugs-platform-plugin-designer/src/test/java/com/willwinder/ugs/nbp/designer/io/gcode/toolpaths/LaserFillToolPathTest.java diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/io/gcode/toolpaths/LaserFillToolPath.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/io/gcode/toolpaths/LaserFillToolPath.java index f20ede69d..1ac25260d 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/io/gcode/toolpaths/LaserFillToolPath.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/io/gcode/toolpaths/LaserFillToolPath.java @@ -12,6 +12,7 @@ import org.locationtech.jts.geom.Envelope; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.LineString; +import org.locationtech.jts.geom.MultiPoint; import java.awt.geom.Area; import java.util.List; @@ -62,6 +63,12 @@ public void appendGcodePath(GcodePath gcodePath, Settings settings) { private static void addLineIntersectionSegments(GcodePath gcodePath, Geometry geometry, LineString lineString, boolean reverse) { Geometry intersection = geometry.intersection(lineString); + + // If the intersection is a multipoint we should not connect the points with a line + if (intersection instanceof MultiPoint) { + return; + } + List geometryCoordinates = ToolPathUtils.geometryToCoordinates(intersection); List partialPosition = geometryCoordinates.stream() .map(numericCoordinate -> PartialPosition.builder(numericCoordinate).build()).toList(); diff --git a/ugs-platform/ugs-platform-plugin-designer/src/test/java/com/willwinder/ugs/nbp/designer/io/gcode/toolpaths/LaserFillToolPathTest.java b/ugs-platform/ugs-platform-plugin-designer/src/test/java/com/willwinder/ugs/nbp/designer/io/gcode/toolpaths/LaserFillToolPathTest.java new file mode 100644 index 000000000..8fdde71c2 --- /dev/null +++ b/ugs-platform/ugs-platform-plugin-designer/src/test/java/com/willwinder/ugs/nbp/designer/io/gcode/toolpaths/LaserFillToolPathTest.java @@ -0,0 +1,52 @@ +package com.willwinder.ugs.nbp.designer.io.gcode.toolpaths; + +import com.willwinder.ugs.nbp.designer.entities.cuttable.Path; +import com.willwinder.ugs.nbp.designer.io.gcode.path.GcodePath; +import com.willwinder.ugs.nbp.designer.io.gcode.path.Segment; +import com.willwinder.ugs.nbp.designer.io.gcode.path.SegmentType; +import com.willwinder.ugs.nbp.designer.model.Settings; +import org.junit.Test; + +import java.util.List; + +import static com.willwinder.ugs.nbp.designer.io.gcode.path.SegmentType.LINE; +import static com.willwinder.ugs.nbp.designer.io.gcode.path.SegmentType.MOVE; +import static com.willwinder.ugs.nbp.designer.io.gcode.path.SegmentType.SEAM; +import static org.junit.Assert.assertEquals; + +public class LaserFillToolPathTest { + + @Test + public void fillToolPathShouldNotConnectThePointEdgesWithALineSegment() { + Path path = new Path(); + path.setPasses(1); + path.moveTo(0,0); + path.lineTo(0, 1); + path.lineTo(1, 1); + path.lineTo(1, 0); + path.lineTo(0.5, 0.5); + path.lineTo(0,0); + path.close(); + + Settings settings = new Settings(); + settings.setMaxSpindleSpeed(10000); + + LaserFillToolPath toolPath = new LaserFillToolPath(settings, path); + toolPath.setStartDepth(0); + toolPath.setTargetDepth(0); + + GcodePath gcodePath = toolPath.toGcodePath(); + List segments = gcodePath.getSegments(); + assertEquals(SEAM, segments.get(0).type); + assertSegment(segments.get(1), MOVE, 1, 0.2); + assertSegment(segments.get(2), LINE, 0.8, 0.2); + assertSegment(segments.get(3), MOVE, 0.2, 0.2); + assertSegment(segments.get(4), LINE, 0.0, 0.2); + } + + private void assertSegment(Segment segment, SegmentType segmentType, double x, double y) { + assertEquals(segmentType, segment.getType()); + assertEquals(x, segment.getPoint().getX(), 0.01); + assertEquals(y, segment.getPoint().getY(), 0.01); + } +}