roundCorners method
void
roundCorners(
{ - double radius = 0.5,
})
Implementation
void roundCorners({double radius = 0.5}) {
var vertices = getVertices();
var arcs = <ArcBetweenPoints>[];
for (var tuple in adjacentNTuples(vertices, 3)) {
var v1 = tuple[0];
var v2 = tuple[1];
var v3 = tuple[2];
var vec1 = v2 - v1;
var vec2 = v3 - v2;
var unitVec1 = vec1.normalize();
var unitVec2 = vec2.normalize();
var angle = vec1.angleBetween(vec2) * radius.sign;
var cutOffLength = radius * tan(angle / 2) / 2;
var sign = vec1.cross(vec2).z.sign;
var arc = ArcBetweenPoints(
start: v2 - unitVec1 * cutOffLength,
end: v2 + unitVec2 * cutOffLength,
angle: sign * angle);
arcs.add(arc);
}
clearPoints();
arcs = [arcs.last, ...withoutLast(arcs)];
for (var arc12 in adjacentPairs(arcs)) {
var arc1 = arc12[0];
var arc2 = arc12[1];
appendPoints(arc1.getPoints());
var line = Line(start: arc1.getEnd(), end: arc2.getStart());
var lengthRatio = line.getLength() / arc1.getArcLength();
line.insertNCurves((lengthRatio * arc1.getNumCurves()).toInt());
appendPoints(line.getPoints());
}
}