Skip to content

Commit

Permalink
Fixed problem with resizing entities when typing zero as width or hei…
Browse files Browse the repository at this point in the history
…ght. (#2354)
  • Loading branch information
breiler authored Oct 23, 2023
1 parent 36a4a13 commit 24d974a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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());
}
Expand Down Expand Up @@ -250,35 +253,31 @@ public void removeAll() {
}

public List<Entity> getChildrenAt(Point2D p) {
List<Entity> 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<Entity> getChildrenIntersecting(Shape shape) {
List<Entity> 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();
}

/**
Expand Down Expand Up @@ -315,17 +314,15 @@ public final List<Entity> getAllChildren() {
return Collections.emptyList();
}

List<Entity> 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
Expand Down

0 comments on commit 24d974a

Please sign in to comment.