use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class CreateRectangleControl method createEntity.
private void createEntity() {
double startX = Math.min(startPosition.getX(), endPosition.getX());
double endX = Math.max(startPosition.getX(), endPosition.getX());
double startY = Math.min(startPosition.getY(), endPosition.getY());
double endY = Math.max(startPosition.getY(), endPosition.getY());
Rectangle rectangle = new Rectangle(startX, startY);
rectangle.setWidth(endX - startX);
rectangle.setHeight(endY - startY);
AddAction addAction = new AddAction(controller, rectangle);
addAction.actionPerformed(new ActionEvent(this, 0, ""));
controller.addEntity(rectangle);
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class SimplePocketTest 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));
SimplePocket simplePocket = new SimplePocket(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), 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);
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class SvgReader method parseRectangle.
private AbstractEntity parseRectangle(Rectangle2D shape) {
Rectangle rectangle = new Rectangle(shape.getX(), shape.getY());
rectangle.setSize(new Size(shape.getWidth(), shape.getHeight()));
return rectangle;
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class EntityGroupTest method scalingGroupShouldScaleChild.
@Test
public void scalingGroupShouldScaleChild() {
EntityGroup entityGroup = new EntityGroup();
Rectangle rectangle = new Rectangle(10, 10);
rectangle.setWidth(10);
rectangle.setHeight(10);
entityGroup.addChild(rectangle);
entityGroup.scale(2, 2);
assertEquals(10, entityGroup.getPosition().getX(), 0.1);
assertEquals(10, entityGroup.getPosition().getY(), 0.1);
assertEquals(20, entityGroup.getSize().getWidth(), 0.1);
assertEquals(20, entityGroup.getSize().getHeight(), 0.1);
assertEquals(10, rectangle.getPosition().getX(), 0.1);
assertEquals(10, rectangle.getPosition().getX(), 0.1);
assertEquals(20, rectangle.getSize().getWidth(), 0.1);
assertEquals(20, rectangle.getSize().getHeight(), 0.1);
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class EntityGroupTest method movingChildrenShouldIgnoreParentLocation.
@Test
public void movingChildrenShouldIgnoreParentLocation() {
EntityGroup entityGroup = new EntityGroup();
entityGroup.move(new Point2D.Double(10, 10));
Rectangle rectangle = new Rectangle(100, 100);
rectangle.setWidth(10);
rectangle.setHeight(10);
entityGroup.addChild(rectangle);
rectangle.move(new Point2D.Double(-5, -5));
rectangle.move(new Point2D.Double(-5, -5));
assertEquals(90, rectangle.getPosition().getX(), 0.1);
assertEquals(90, rectangle.getPosition().getY(), 0.1);
assertEquals(90, entityGroup.getPosition().getX(), 0.1);
assertEquals(90, entityGroup.getPosition().getX(), 0.1);
}
Aggregations