use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class SelectionManagerTest method moveShouldMoveAllEntites.
@Test
public void moveShouldMoveAllEntites() {
Rectangle firstEntity = new Rectangle();
firstEntity.setPosition(new Point2D.Double(10, 20));
firstEntity.setSize(new Size(10, 10));
target.addSelection(firstEntity);
Rectangle secondEntity = new Rectangle();
secondEntity.setPosition(new Point2D.Double(20, 30));
secondEntity.setSize(new Size(40, 40));
target.addSelection(secondEntity);
target.move(new Point2D.Double(10, 10));
assertEquals(50, target.getSize().getWidth(), 0.1);
assertEquals(50, target.getSize().getHeight(), 0.1);
assertEquals(new Point2D.Double(20, 30), target.getPosition());
assertEquals(new Point2D.Double(45, 55), target.getCenter());
assertEquals(0, target.getRotation(), 0.1);
assertEquals(new Point2D.Double(20, 30), firstEntity.getPosition());
assertEquals(new Point2D.Double(30, 40), secondEntity.getPosition());
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class DrillCenterToolPathTest method drillCenterShouldDrillInCenterOfShape.
@Test
public void drillCenterShouldDrillInCenterOfShape() {
Rectangle rectangle = new Rectangle();
rectangle.setSize(new Size(15, 15));
rectangle.setPosition(new Point2D.Double(10, 10));
DrillCenterToolPath drillCenterToolPath = new DrillCenterToolPath(rectangle);
drillCenterToolPath.setDepthPerPass(10);
drillCenterToolPath.setTargetDepth(10);
GcodePath gcodePath = drillCenterToolPath.toGcodePath();
assertEquals(8, gcodePath.getSegments().size());
assertEquals(SegmentType.MOVE, gcodePath.getSegments().get(0).type);
assertEquals(SegmentType.MOVE, gcodePath.getSegments().get(1).type);
assertEquals(SegmentType.MOVE, gcodePath.getSegments().get(2).type);
assertEquals(SegmentType.POINT, gcodePath.getSegments().get(3).type);
assertEquals(0, gcodePath.getSegments().get(3).point.getZ(), 0.01);
assertEquals(SegmentType.POINT, gcodePath.getSegments().get(4).type);
assertEquals(17.5, gcodePath.getSegments().get(4).point.getX(), 0.01);
assertEquals(17.5, gcodePath.getSegments().get(4).point.getY(), 0.01);
assertEquals(0, gcodePath.getSegments().get(4).point.getZ(), 0.01);
assertEquals(SegmentType.POINT, gcodePath.getSegments().get(5).type);
assertEquals(-10, gcodePath.getSegments().get(5).point.getZ(), 0.01);
assertEquals(SegmentType.POINT, gcodePath.getSegments().get(6).type);
assertEquals(0, gcodePath.getSegments().get(6).point.getZ(), 0.01);
assertEquals(SegmentType.MOVE, gcodePath.getSegments().get(7).type);
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class PocketToolPathTest method pocketShouldNotExceedTheGeometry.
@Test
public void pocketShouldNotExceedTheGeometry() {
double toolRadius = 2.5;
double geometrySize = 10d;
double safeHeight = 1;
double targetDepth = -10;
int depthPerPass = 1;
Rectangle rectangle = new Rectangle();
rectangle.setSize(new Size(geometrySize, geometrySize));
PocketToolPath simplePocket = new PocketToolPath(rectangle);
simplePocket.setTargetDepth(targetDepth);
simplePocket.setDepthPerPass(depthPerPass);
simplePocket.setToolDiameter(toolRadius * 2);
simplePocket.setStepOver(1);
simplePocket.setSafeHeight(safeHeight);
List<Segment> segmentList = simplePocket.toGcodePath().getSegments();
Segment firstSegment = segmentList.get(0);
assertEquals("The first segment should move to safe height", safeHeight, firstSegment.point.getAxis(Axis.Z), 0.1);
assertFalse("The first segment should not move X", firstSegment.point.hasAxis(Axis.X));
assertFalse("The first segment should not move Y", firstSegment.point.hasAxis(Axis.Y));
Segment secondSegment = segmentList.get(1);
assertEquals("The second segment should move to safe height", safeHeight, firstSegment.point.getAxis(Axis.Z), 0.1);
assertEquals("The second segment should move to first X position", safeHeight, secondSegment.point.getAxis(Axis.X), toolRadius);
assertEquals("The second segment should move to first Y position", safeHeight, secondSegment.point.getAxis(Axis.Y), toolRadius);
// Make sure that we don't move outside the boundary of the geometry
segmentList.stream().filter(segment -> segment.type == SegmentType.LINE || segment.type == SegmentType.POINT).forEach(segment -> {
assertTrue("Point was outside boundary of 10x10 shape: X=" + segment.getPoint().getAxis(Axis.X), segment.getPoint().getAxis(Axis.X) >= toolRadius);
assertTrue("Point was outside boundary of 10x10 shape: Y=" + segment.getPoint().getAxis(Axis.Y), segment.getPoint().getAxis(Axis.Y) >= toolRadius);
assertTrue("Point was outside boundary of 10x10 shape: X=" + segment.getPoint().getAxis(Axis.X), segment.getPoint().getAxis(Axis.X) <= geometrySize - toolRadius);
assertTrue("Point was outside boundary of 10x10 shape: Y=" + segment.getPoint().getAxis(Axis.Y), segment.getPoint().getAxis(Axis.Y) <= geometrySize - toolRadius);
assertTrue("Point was outside boundary of 10x10 shape: Z=" + segment.getPoint().getAxis(Axis.Z), segment.getPoint().getAxis(Axis.Z) <= 0);
assertTrue("Point was outside boundary of 10x10 shape: Z=" + segment.getPoint().getAxis(Axis.Z), segment.getPoint().getAxis(Axis.Z) >= targetDepth);
});
List<Segment> drillOperations = segmentList.stream().filter(segment -> segment.type == SegmentType.POINT).collect(Collectors.toList());
assertEquals("There should be a number of drill operations when making a pocket", Math.abs((targetDepth - depthPerPass) / depthPerPass), drillOperations.size(), 0.1);
PartialPosition point = drillOperations.get(drillOperations.size() - 1).getPoint();
assertEquals("Last operation should reach the target depth", targetDepth, point.getAxis(Axis.Z), 0.1);
}
Aggregations