Skip to content

Commit f79642e

Browse files
committed
Fix: 'Should Lift Pen' not being respected / preventing drawings from completing #146
- Note: Should lift pen, only shows the 'moves' the path finding module had to take, there is still work to be done to create a continuous line PFM
1 parent 184a251 commit f79642e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/java/drawingbot/pfm/AbstractSketchPFM.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public abstract class AbstractSketchPFM extends AbstractDarkestPFM {
3737
public double lineProgress = 0;
3838
public double lumProgress = 0;
3939
public double actualProgress = 0;
40+
public int squiggleCount = 0;
4041

4142
// ERASING \\
4243
public float radiusMin = 1F, radiusMax = 4F;
@@ -113,15 +114,15 @@ public void run() {
113114
findDarkestPixelMethod.accept(tools.getPixelData(), context.current);
114115

115116
// Create a linking geometry, to draw this forced pen move
116-
if(!shouldLiftPen && context.hasResult()){
117+
if(!shouldLiftPen && squiggleCount > 0 && context.last[0] != context.current[0] && context.last[1] != context.current[1]){
117118
addLinkingGeometry(tools.getPixelData(), context.last, context.current);
118119
}
119120

120121
beginSquiggle();
121122

122123
// Keep track of the squiggle's deviation
123124
float initialDarkness = tools.getPixelData().getLuminance(context.getX(), context.getY());
124-
float allowableDarkness = !shouldLiftPen ? Float.MAX_VALUE : initialDarkness + Math.max(1, 255 * squiggleMaxDeviation);
125+
float allowableDarkness = !shouldLiftPen ? desiredLuminance : initialDarkness + Math.max(1, desiredLuminance * squiggleMaxDeviation);
125126
boolean failed = false;
126127

127128
// Run the loop until it is stopped in the case of should lift pen, or run it until the maximum squiggle length if we should lift the pen
@@ -149,6 +150,11 @@ public void run() {
149150

150151
}
151152

153+
if(!shouldLiftPen && context.getAvgLuminance() > allowableDarkness){
154+
failed = true;
155+
break;
156+
}
157+
152158
// The generated geometry has passed all our tests, add it too the drawing & update the context
153159
addPathFindingResult(context, tools.getPixelData());
154160
context.last = context.getPosition();
@@ -188,7 +194,7 @@ public void beginSquiggle(){
188194
}
189195

190196
public void endSquiggle(){
191-
197+
squiggleCount++;
192198
}
193199

194200
protected boolean updateProgress(PlottingTools tools){

0 commit comments

Comments
 (0)