From 24d974a5b8260c1597c94b8a62f0d50dc41df8cc Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Mon, 23 Oct 2023 20:00:40 +0200 Subject: [PATCH] Fixed problem with resizing entities when typing zero as width or height. (#2354) --- .../nbp/designer/entities/AbstractEntity.java | 8 ++--- .../nbp/designer/entities/EntityGroup.java | 35 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/AbstractEntity.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/AbstractEntity.java index 6d43116754..f6a1a4d7c6 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/AbstractEntity.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/AbstractEntity.java @@ -85,12 +85,12 @@ public Size getSize() { @Override public void setSize(Size size) { - if (size.getWidth() < 0.1) { - size = new Size(0.1, size.getHeight()); + if (size.getWidth() <= 0) { + size = new Size(0.0001, size.getHeight()); } - if (size.getHeight() < 0.1) { - size = new Size(size.getWidth(), 0.1); + if (size.getHeight() <= 0) { + size = new Size(size.getWidth(), 0.0001); } Size currentSize = getSize(); diff --git a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityGroup.java b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityGroup.java index b557a8b29b..ecefd74088 100644 --- a/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityGroup.java +++ b/ugs-platform/ugs-platform-plugin-designer/src/main/java/com/willwinder/ugs/nbp/designer/entities/EntityGroup.java @@ -32,7 +32,6 @@ This file is part of Universal Gcode Sender (UGS). import java.util.List; import java.util.Optional; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -57,6 +56,10 @@ public void render(Graphics2D graphics, Drawing drawing) { @Override public void setSize(Size size) { + if(size.getWidth() == 0 || size.getHeight() == 0) { + return; + } + Size originalSize = getSize(); scale(size.getWidth() / originalSize.getWidth(), size.getHeight() / originalSize.getHeight()); } @@ -250,35 +253,31 @@ public void removeAll() { } public List getChildrenAt(Point2D p) { - List result = this.children + return this.children .stream() .flatMap(s -> { - if (s instanceof EntityGroup) { - return ((EntityGroup) s).getChildrenAt(p).stream(); + if (s instanceof EntityGroup entityGroup) { + return entityGroup.getChildrenAt(p).stream(); } else if (s.isWithin(p)) { return Stream.of(s); } else { return Stream.empty(); } - }).collect(Collectors.toList()); - - return Collections.unmodifiableList(result); + }).toList(); } public List getChildrenIntersecting(Shape shape) { - List result = this.children + return this.children .stream() .flatMap(s -> { - if (s instanceof EntityGroup) { - return ((EntityGroup) s).getChildrenIntersecting(shape).stream(); + if (s instanceof EntityGroup entityGroup) { + return entityGroup.getChildrenIntersecting(shape).stream(); } else if (s.isIntersecting(shape)) { return Stream.of(s); } else { return Stream.empty(); } - }).collect(Collectors.toList()); - - return Collections.unmodifiableList(result); + }).toList(); } /** @@ -315,17 +314,15 @@ public final List getAllChildren() { return Collections.emptyList(); } - List result = this.children + return this.children .stream() .flatMap(s -> { - if (s instanceof EntityGroup) { - return ((EntityGroup) s).getAllChildren().stream(); + if (s instanceof EntityGroup entityGroup) { + return entityGroup.getAllChildren().stream(); } else { return Stream.of(s); } - }).collect(Collectors.toList()); - - return Collections.unmodifiableList(result); + }).toList(); } @Override