After weeks of implementing different types of segments and the method to intersect them, I needed a bit of a palate cleanser.
I implemented something I had done with maker.js - a dieline for a box, but this time using pantograph. You can find it in this observableHQ notebook, as well as in the example folder of pantograph
It helped me refine my opinions on how Strands
need to be handled in the
library. I have added function to work with them.
Generally, it feels easy to manipulate these objects (way easier than with maker.js). But I’m the one who has built the thing, so I’d be curious if someone would try and tell me where it does fit only my brain!
New methods to work with Strands
Boolean on Strands
There are two new boolean operations, that work with strands: eraseStrand
and
confineStrand
. They do boolean operations on the strand by remove parts of it
– either the parts that are within a diagram (erase) or outside (confine). I am
open to new terminologies!
There is also new methods on most objects to figure out parts of their stroke that is common - these are returned as an array of strands (or segments).
Use within the Dieline
class
In order to build my box, I created a higher level structure for… dielines.
It consists of a body which is a Diagram
(i.e. has an interior and an
exterior). But also cuts and folds, which are arrays of strands.
If you look at the fuseFold
method, you will see overlappingStrands
used. In
this method I fuse another dieline, but transform common segments into folds.
The cutShape
method uses eraseStrand
. If you cut a shape within a dieline, you
also want the fold lines to be cut.
Stroke outline of Strands
Another use case I wanted to implement for strands is the creation of stroke outlines. Any curve can be understood as a shape without thickness. In the case of a loop, it is the boundary of a surface, for a folds in the dieline example, a strand is a single cut.
But, a curve can be the representation of a line which has a stroke width - in
that case a surface. The outlineStroke
function can transform a Strand
into
a Diagram
, by giving it a thickness.
This is also valid for loops – and the outlineStroke
method also supports
shapes with an interior as input.
Bugs and the boolean algorithm
As I mentionned last week, the mandala example was showing some bug. It took me a little while but I found most of them.
There was some logic in the tangent arcs that was broken in subtle ways.
Most importantly, it was a manifestation of some assumption I made in my algorithms that were wrong. I build a list of matching segments with same start and end and then decide which one I keep or not.
This might make it more robust in some cases (to be actually tested at some point). But the assumption is also wrong. There are some cases where such a match is not possible. I now handle it by stitching segments after choosing which ones I keep or not. I should actually look at the literature on the topic, instead of just using my own baked stuff.