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

Fixed problem with resizing entities when typing zero as width or height #2354

Merged
merged 1 commit into from
Oct 23, 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
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