PolygonOffsetter
Package: Libraries.Fabrication.Geometry · Inherits from: Libraries.Language.Object
The PolygonOffsetter class moves closed loops inward or outward by a fixed distance. Each corner is moved along the bisector of its two edges; corners turning away from the material get a rounded arc (16 degree steps) and very sharp ones a plain link, and PolygonOperations then keeps whatever winds positively, which trims the folds. The sign follows the material, which lies on the left of every loop: a positive distance shrinks the material (an inset), a negative one grows it (an outset).
Example Code
use Libraries.Containers.Array
use Libraries.Fabrication.Geometry.Contour
use Libraries.Fabrication.Geometry.PolygonOffsetter
class Main
action Main
Array<Contour> outline // one layer's loops, from ContourGenerator
PolygonOffsetter offsetter
Array<Contour> wall = offsetter:Offset(outline, 0.2) // 0.2 mm inside
Array<Contour> brim = offsetter:Offset(outline, -3.0) // 3 mm outside
end
end
Actions
Offset(Libraries.Containers.Array<Libraries.Fabrication.Geometry.Contour> loops, number distance)
Offsets every closed loop of a layer. Open paths and loops of fewer than 3 points are ignored.
Parameters
loopsLibraries.Containers.Array<Libraries.Fabrication.Geometry.Contour>: Loops on one plane (the first loop's plane is used for the result).distancenumber: How far to move (mm): positive moves into the material, negative away from it.
Returns
Libraries.Containers.Array<Libraries.Fabrication.Geometry.Contour>: The offset loops; copies of the input for a distance of 0.
Example
use Libraries.Containers.Array
use Libraries.Fabrication.Geometry.Contour
use Libraries.Fabrication.Geometry.PolygonOffsetter
Contour square
square:AddPoint(0, 0)
square:AddPoint(20, 0)
square:AddPoint(20, 20)
square:AddPoint(0, 20)
square:closed = true
Array<Contour> outline
outline:Add(square)
PolygonOffsetter offsetter
Array<Contour> inset = offsetter:Offset(outline, 0.2) // 0.2 mm in: an outer wall's centre line
Contour wall = inset:Get(0)
output wall:Area() // 384.16, a 19.6 mm square