use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class EntityGroupTest method scalingGroupShouldScaleChildrenAndTheirRelativePosition.
@Test
public void scalingGroupShouldScaleChildrenAndTheirRelativePosition() {
EntityGroup entityGroup = new EntityGroup();
Rectangle rectangle1 = new Rectangle(10, 10);
rectangle1.setWidth(10);
rectangle1.setHeight(10);
entityGroup.addChild(rectangle1);
Rectangle rectangle2 = new Rectangle(20, 20);
rectangle2.setWidth(10);
rectangle2.setHeight(10);
entityGroup.addChild(rectangle2);
entityGroup.scale(2, 2);
assertEquals(10, rectangle1.getPosition().getX(), 0.1);
assertEquals(10, rectangle1.getPosition().getX(), 0.1);
assertEquals(20, rectangle1.getSize().getWidth(), 0.1);
assertEquals(20, rectangle1.getSize().getHeight(), 0.1);
assertEquals(30, rectangle2.getPosition().getX(), 0.1);
assertEquals(30, rectangle2.getPosition().getX(), 0.1);
assertEquals(20, rectangle2.getSize().getWidth(), 0.1);
assertEquals(20, rectangle2.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 setRotationShouldRotateChildrenAsWell.
@Test
public void setRotationShouldRotateChildrenAsWell() {
EntityGroup entityGroup = new EntityGroup();
Rectangle rectangle1 = new Rectangle(10, 0);
rectangle1.setWidth(1);
rectangle1.setHeight(1);
entityGroup.addChild(rectangle1);
Rectangle rectangle2 = new Rectangle(0, 0);
rectangle2.setWidth(1);
rectangle2.setHeight(1);
entityGroup.addChild(rectangle2);
entityGroup.setRotation(90);
assertEquals(5, rectangle1.getPosition().getX(), 0.1);
assertEquals(-5, rectangle1.getPosition().getY(), 0.1);
assertEquals(90, rectangle1.getRotation(), 0.1);
assertEquals(5, rectangle2.getPosition().getX(), 0.1);
assertEquals(5, rectangle2.getPosition().getY(), 0.1);
assertEquals(90, rectangle2.getRotation(), 0.1);
assertEquals(90, entityGroup.getRotation(), 0.1);
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class MoveControlTest method moveEntityShouldWorkOnScaledEntities.
@Test
public void moveEntityShouldWorkOnScaledEntities() {
Rectangle rectangle = new Rectangle();
rectangle.setWidth(10);
rectangle.setHeight(10);
rectangle.applyTransform(AffineTransform.getScaleInstance(2, 2));
SelectionManager selectionManager = new SelectionManager();
selectionManager.addSelection(rectangle);
Controller controller = new Controller(selectionManager, new SimpleUndoManager());
MoveControl target = new MoveControl(controller);
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_PRESSED, new Point2D.Double(10, 10), new Point2D.Double(10, 10)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(12, 12)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_RELEASED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
Assert.assertEquals(1, rectangle.getPosition().getX(), 0.1);
Assert.assertEquals(1, rectangle.getPosition().getY(), 0.1);
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class MoveControlTest method moveEntityShouldUseGlobalTransform.
@Test
public void moveEntityShouldUseGlobalTransform() {
Rectangle rectangle = new Rectangle();
rectangle.setWidth(10);
rectangle.setHeight(10);
rectangle.move(new Point2D.Double(10, 10));
EntityGroup entityGroup = new EntityGroup();
entityGroup.addChild(rectangle);
entityGroup.move(new Point2D.Double(10, 10));
SelectionManager selectionManager = new SelectionManager();
selectionManager.addSelection(rectangle);
Controller controller = new Controller(selectionManager, new SimpleUndoManager());
MoveControl target = new MoveControl(controller);
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_PRESSED, new Point2D.Double(10, 10), new Point2D.Double(10, 10)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(12, 12)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_DRAGGED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
target.onEvent(new MouseEntityEvent(target, EventType.MOUSE_RELEASED, new Point2D.Double(10, 10), new Point2D.Double(11, 11)));
Assert.assertEquals(21, rectangle.getPosition().getX(), 0.1);
Assert.assertEquals(21, rectangle.getPosition().getY(), 0.1);
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle in project Universal-G-Code-Sender by winder.
the class RectangleTest method setRotationShouldRotateAroundItsCenter.
@Test
public void setRotationShouldRotateAroundItsCenter() {
Rectangle rectangle = new Rectangle(10, 10);
rectangle.setWidth(10);
rectangle.setHeight(10);
assertEquals(Double.valueOf(15), Double.valueOf(rectangle.getCenter().getX()));
assertEquals(Double.valueOf(15), Double.valueOf(rectangle.getCenter().getY()));
rectangle.setRotation(90);
assertEquals(Double.valueOf(15), Double.valueOf(rectangle.getCenter().getX()));
assertEquals(Double.valueOf(15), Double.valueOf(rectangle.getCenter().getY()));
}
Aggregations