Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for SVG import #2151

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<ugs.surefire.version>3.0.0-M5</ugs.surefire.version>
<download-maven-plugin.version>1.3.0</download-maven-plugin.version>
<mockito.version>3.2.4</mockito.version>
<batik.version>1.14</batik.version>
<batik.version>1.16</batik.version>
<jxmodem.version>0.1a</jxmodem.version>
<jts.version>1.19.0</jts.version>
<ugs.maven-resources-plugin.version>3.1.0</ugs.maven-resources-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This file is part of Universal Gcode Sender (UGS).
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.RectangularShape;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
Expand All @@ -44,6 +44,7 @@ public class EntityGroup extends AbstractEntity implements EntityListener {

private double groupRotation = 0;
private Point2D cachedCenter = new Point2D.Double(0, 0);
private Rectangle2D cachedBounds = new Rectangle2D.Double(0, 0, 0, 0);

public EntityGroup() {
super();
Expand Down Expand Up @@ -87,12 +88,34 @@ public void rotate(Point2D center, double angle) {

@Override
public Shape getShape() {
final Area area = new Area();
return getBounds();
}

@Override
public Size getSize() {
Rectangle2D bounds = getBounds();
return new Size(bounds.getWidth(), bounds.getHeight());
}

@Override
public Rectangle2D getBounds() {
if (cachedBounds != null) {
return cachedBounds;
}

List<Entity> allChildren = getAllChildren();
allChildren.stream()
.filter(c -> c != this)
.forEach(c -> area.add(new Area(c.getBounds())));
return area.getBounds2D();
double maxX = allChildren.stream().map(Entity::getBounds).mapToDouble(RectangularShape::getMaxX).max().orElse(0);
double maxY = allChildren.stream().map(Entity::getBounds).mapToDouble(RectangularShape::getMaxY).max().orElse(0);
double minX = allChildren.stream().map(Entity::getBounds).mapToDouble(RectangularShape::getMinX).min().orElse(0);
double minY = allChildren.stream().map(Entity::getBounds).mapToDouble(RectangularShape::getMinY).min().orElse(0);
cachedBounds = new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY);
return cachedBounds;
}

@Override
public Point2D getPosition(Anchor anchor) {
Rectangle2D bounds = getBounds();
return new Point2D.Double(bounds.getX(), bounds.getY());
}

@Override
Expand Down Expand Up @@ -124,12 +147,13 @@ public void addChild(Entity entity, int index) {

private void invalidateCenter() {
cachedCenter = null;
cachedBounds = null;
}

@Override
public Point2D getCenter() {
if (cachedCenter == null) {
Rectangle2D bounds = getShape().getBounds2D();
Rectangle2D bounds = getBounds();
cachedCenter = new Point2D.Double(bounds.getCenterX(), bounds.getCenterY());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Rectangle() {
*/
public Rectangle(double x, double y) {
super(x, y);
this.shape = new Rectangle2D.Double(0, 0, 10, 10);
this.shape = new Rectangle2D.Double(0, 0, 1, 1);
setName("Rectangle");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,7 @@ public void changedUpdate(DocumentEvent e) {
double width = Utils.parseDouble(widthTextField.getText());
double height = Utils.parseDouble(heightTextField.getText());

if (width <= 0 || height <= 0) {
return;
}

if (!lockRatioButton.isSelected()) {
if (width >= 0 && height >= 0 & !lockRatioButton.isSelected()) {
double ratio = controller.getSelectionManager().getSize().getRatio();
if (e.getDocument() == widthTextField.getDocument()) {
height = width / ratio;
Expand Down
Loading