From 95b569b1a5565799fdd0f0ac55b422cac4b90a76 Mon Sep 17 00:00:00 2001 From: Sandy Noble Date: Fri, 22 Aug 2014 19:13:41 +0100 Subject: [PATCH] Shapes that go off the drawing area no longer cause long joining lines when they re-appear. PictureFrame now crops the vector art. --- DisplayMachine.pde | 19 ++++++- drawing.pde | 139 +++++++++++++++++++++++++++------------------ 2 files changed, 101 insertions(+), 57 deletions(-) diff --git a/DisplayMachine.pde b/DisplayMachine.pde index 93c0da4..56090c6 100644 --- a/DisplayMachine.pde +++ b/DisplayMachine.pde @@ -519,21 +519,34 @@ class DisplayMachine extends Machine { if (pointPaths[i] != null) { - beginShape(); + boolean inShape = false; for (int j = 0; j pathLengthHighPassCutoff) { - List filteredPoints = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength, scaling, position); - if (!filteredPoints.isEmpty()) + List> filteredPaths = filterPoints(pointPaths[i], VECTOR_FILTER_LOW_PASS, minimumVectorLineLength, scaling, position); + for (List filteredPoints : filteredPaths) { - // draw the first one with a pen up and down to get to it - PVector p = filteredPoints.get(0); - if ( p.x == lastPoint.x && p.y == lastPoint.y ) - liftToGetToNewPoint = false; - else - liftToGetToNewPoint = true; - - // pen UP! (IF THE NEW POINT IS DIFFERENT FROM THE LAST ONE!) - if (liftToGetToNewPoint) - addToCommandQueue(CMD_PENUP+"END"); - // move to this point and put the pen down - command = CMD_CHANGELENGTHDIRECT+(int)p.x+","+(int)p.y+","+getMaxSegmentLength()+",END"; - addToCommandQueue(command); - if (liftToGetToNewPoint) - addToCommandQueue(CMD_PENDOWN+"END"); - - - - // then just iterate through the rest - for (int j=1; j removeShortPaths(List list, int cutoff) return list; } -List filterPoints(RPoint[] points, int filterToUse, long filterParam, float scaling, PVector position) +List> filterPoints(RPoint[] points, int filterToUse, long filterParam, float scaling, PVector position) { return filterPointsLowPass(points, filterParam, scaling, position); } -List filterPointsLowPass(RPoint[] points, long filterParam, float scaling, PVector position) +List> filterPointsLowPass(RPoint[] points, long filterParam, float scaling, PVector position) { - List result = new ArrayList(); + List> result = new ArrayList>(); - // scale and convert all the points first - List scaled = new ArrayList(points.length); + // scale and convert all the points first, and filter them by area. + List> areaFiltered = new ArrayList>(); + List scaledPoints = null; for (int j = 0; j filterPointsLowPass(RPoint[] points, long filterParam, float scali p = PVector.mult(p, scaling); p = PVector.add(p, position); p = getDisplayMachine().inSteps(p); - if (getDisplayMachine().getPage().surrounds(p)) + + // Check if the point is on the drawable area + if (getDisplayMachine().getPictureFrame().surrounds(p)) { - p = getDisplayMachine().asNativeCoords(p); - scaled.add(p); - } - } - - if (scaled.size() > 1) - { - PVector p = scaled.get(0); - result.add(p); - - for (int j = 1; j filterParam || abs(diffy) > filterParam) + if (scaledPoints == null) { - //println("Adding point " + p + ", last: " + result.get(result.size()-1)); - result.add(p); + scaledPoints = new ArrayList(points.length); + } + p = getDisplayMachine().asNativeCoords(p); + scaledPoints.add(p); + } + else + { // if the point is NOT in the drawable area, then check to see if there is a + // scaledPoints list, and if there is, that means this is the first point in + // the current path that is NOT in the drawable area. That is, the line was on + // the drawable area, but it's just gone off it. + // In this case, append the current list of scaled points into the results list, + // and then nullify scaledPoints so it'll be restarted as a new list if a + // subsequent point ends up coming back on the drawable area. + if (scaledPoints != null && scaledPoints.size() > 0) + { + areaFiltered.add(scaledPoints); + scaledPoints = null; } } } - if (result.size() < 2) - result.clear(); - //println("finished filter."); + // Now filter by length + if (!areaFiltered.isEmpty()) + { + for (List filteredPoints : areaFiltered) + { + List lengthFiltered = new ArrayList(); + PVector p = filteredPoints.get(0); + lengthFiltered.add(p); + + for (int j = 1; j filterParam || abs(diffy) > filterParam) + { + //println("Adding point " + p + ", last: " + result.get(result.size()-1)); + lengthFiltered.add(p); + } + } + if (lengthFiltered.size() >= 2) + { + result.add(lengthFiltered); + } + } + } + + println("finished filter."); return result; }