Editing BezierPaths directly



  • For reasons I can explain in detail if needed, I'd like to edit the oncurve points of a BezierPath before drawing the path, checking each point in turn to make sure its coordinates fall on an implied alignment grid and correcting it as needed.

    Two methods that apparently don't work are:

    for pt in path.onCurvePoints:
         if test(pt[0]) == Fail or test(pt[1]) == Fail:
              pt = (correctedCoordinate, correctedCoordinate)
    

    and

    for pt in range(len(path.onCurvePoints)):
         if test(path.onCurvePoints[pt][0]) == Fail or 
              test(path.onCurvePoints[pt][1]) == Fail:
              path.onCurvePoints[pt] = (correctedCoordinate, 
                   correctedCoordinate)
    

  • admin

    The attributes onCurvePoints of a bezierPath is a immutable representation of the path points.

    I would like to encourage you to look at pens and how to alter point data and point structures while drawing in a pen.

    see

    A drawBot BezierPath is also a pen.



  • I thought after I posted that pens would be part of a more elegant solution—my problem reminded me of some things Just has shown me, and I recall pens coming up in that conversation.

    The fix I did find was to create a function that creates and returns a new path from the uncorrected path contour by contour and segment by segment, correcting points as needed by rounding to the nearest implied-grid increment. But now that classes are out I'll take the time to learn about pens (finally).

    I'd still like to figure out why I was having the problem in the first place. At 1000pt the glyphs in Kast, my font I've been working with, are all exactly 692pt wide. With the proper linespacing and every other line offset 346pt (the width of the <space> glyph) all the points in adjacent glyphs horizontally and vertically should match exactly to allow me to combine their paths seamlessly.

    Looking at the errors—maybe I'll put the analyses up in another post, I saved my test code—I felt like there was something about the formatted string that was introducing systematic misalignment, and removeOverlap() was also doing some math that threw off some points in the combined paths.


  • admin

    The documentation is adjusted and path.onCurvePoints and path.offCurvePoints and the path contours are immutable now.

    see https://github.com/typemytype/drawbot/pull/350


Log in to reply