Skip to content

Commit b7d34cb

Browse files
committed
more exception testing
1 parent 8b18150 commit b7d34cb

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PathImageMask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void update() {
6161

6262
for (LineSegment2D line : lines) {
6363
scanLine(src, line, s, c);
64-
setComplete(i++ * 100 / size);
64+
setComplete(i++ * 99 / size);
6565
}
6666

6767
Turtle resultAbove = new Turtle();

src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PrintTurtle.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public void update() {
5353
if (myTurtle == null || myTurtle.history.isEmpty()) return;
5454

5555
generatePolylines(myTurtle);
56+
} catch(Exception e) {
57+
logger.error("Failed to update", e);
5658
} finally {
5759
lock.unlock();
5860
}
@@ -68,12 +70,14 @@ public void print(Graphics g) {
6870
GraphViewPanel.setHints(g2);
6971
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
7072
g2.setStroke(new BasicStroke(lineThickness.getValue()));
73+
7174
lock.lock();
7275
try {
7376
polylines.forEach(p -> p.draw(g2));
7477
} finally {
7578
lock.unlock();
7679
}
80+
7781
g2.dispose();
7882
}
7983

src/main/java/com/marginallyclever/makelangelo/makeart/io/TurtleFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public static JFileChooser getSaveFileChooser() {
7171
}
7272

7373
public static Turtle load(String filename) throws Exception {
74-
if(filename == null || filename.trim().isEmpty()) throw new InvalidParameterException("filename cannot be empty");
74+
if(filename == null || filename.trim().isEmpty()) {
75+
throw new InvalidParameterException("filename cannot be empty");
76+
}
7577

7678
for( TurtleLoader loader : loaders ) {
7779
if(isValidExtension(filename,loader.getFileNameFilter())) {

src/main/java/com/marginallyclever/makelangelo/turtle/Turtle.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -439,30 +439,35 @@ public void addLineSegments(LineCollection segments) {
439439
*/
440440
public void addLineSegments(LineCollection segments, double minimumJumpSize, double minDrawDistance) {
441441
if(segments.isEmpty()) return;
442-
443-
LineSegment2D first = segments.get(0);
444-
jumpTo(first.start.x,first.start.y);
445-
moveTo(first.end.x,first.end.y);
446-
447-
double minJumpSquared = minimumJumpSize*minimumJumpSize;
448-
double minDrawSquared = minDrawDistance*minDrawDistance;
449-
450-
for( LineSegment2D line : segments ) {
451-
// change color if needed
452-
if(line.color !=getColor()) {
453-
setColor(line.color);
454-
}
455442

456-
double d = distanceSquared(line.start);
457-
if(d > minJumpSquared) {
458-
// The previous line ends too far from the start point of this line,
459-
// need to make a travel with the pen up to the start point of this line.
460-
jumpTo(line.start.x,line.start.y);
461-
} else if(d>minDrawSquared) {
462-
moveTo(line.start.x,line.start.y);
443+
lock();
444+
try {
445+
LineSegment2D first = segments.get(0);
446+
jumpTo(first.start.x, first.start.y);
447+
moveTo(first.end.x, first.end.y);
448+
449+
double minJumpSquared = minimumJumpSize * minimumJumpSize;
450+
double minDrawSquared = minDrawDistance * minDrawDistance;
451+
452+
for (LineSegment2D line : segments) {
453+
// change color if needed
454+
if (line.color != getColor()) {
455+
setColor(line.color);
456+
}
457+
458+
double d = distanceSquared(line.start);
459+
if (d > minJumpSquared) {
460+
// The previous line ends too far from the start point of this line,
461+
// need to make a travel with the pen up to the start point of this line.
462+
jumpTo(line.start.x, line.start.y);
463+
} else if (d > minDrawSquared) {
464+
moveTo(line.start.x, line.start.y);
465+
}
466+
// Make a pen down move to the end of this line
467+
moveTo(line.end.x, line.end.y);
463468
}
464-
// Make a pen down move to the end of this line
465-
moveTo(line.end.x,line.end.y);
469+
} finally {
470+
unlock();
466471
}
467472
}
468473

0 commit comments

Comments
 (0)