Skip to content

Geometric Base Types

Jaime van Kessel edited this page Apr 19, 2024 · 5 revisions

A lot of 2D geometric operations are processed all around CuraEngine. For this to work and be understandable, we need geometric classes that are easy to use, explicit and performant.

classDiagram
PointsSet *-- "*" Point2LL : points_
PointsSet : +begin()
PointsSet : +end()
PointsSet : +translate()

Point2LL : +x
Point2LL : +y

PointsSet <|-- Polyline
Polyline : +beginSegments() SegmentIterator
Polyline : +endSegments() SegmentIterator
Polyline : +abstract_addClosingSegment() bool
Polyline : +abstract_segmentsCount() int
Polyline : +abstract_isValid() bool
<<Abstract>> Polyline

Polyline <|-- ClosedPolyline
ClosedPolyline : +bool explicitelyClosed

Polyline <|-- OpenPolyline

ClosedPolyline  <|-- Polygon
Polygon : +area() double

vector <|-- MixedLinesSet
MixedLinesSet o-- "*" Polyline

LinesSet *-- "*" Polyline
<<Template>> LinesSet

LinesSet <|-- ClosedLinesSet
ClosedLinesSet ..> ClosedPolyline

LinesSet <|-- OpenLinesSet
OpenLinesSet ..> OpenPolyline

LinesSet <|-- Shape
Shape ..> Polygon

Shape <|-- SingleShape
Loading

PointsSet

A PointsSet is just a generic container of points. It provides some global transform methods, and iterator to be used as a standard container. Geometrically, the points have no specific relation to each other.

geometry-points-set

Polyline

A Polyline inherits PointsSet. When using a Polyline, we consider that each points is linked to the previous one by a segment, forming a continuous line. In a Polyline, the points order matters. This is abstract as one should always use either OpenPolyLine or ClosedPolyLine

OpenPolyline

An OpenPolyline considers the list of points as is. Each point is linked to the previous one in the list. It may happen that the first and last point are at the same position, somehow forming a closed line, but not considered as such.

geometry-open-polyline

ClosedPolyline

Geometrically, a ClosedPolyline is different from an open one because we can differentiate an inner and outer relative to the line. A point can be "inside" or "outside"

Explicitely closed

An explicitely closed Polyline has an extra ending point at the same position of the starting point. However it is a bit hard to ensure that the ending and starting point are always at the very same position, so it is actually possible to create inconsistent lines with this representation. This type of line should not be used for new developments.

geometry-exp-closed-polyline

Implicitely closed

An implicitely closed polyline considers an extra segment between the last and first points in the list. Thus it is always closed and will remain consistent. It is also good to note that ClipperLib always expects and returns this kind of closed line.

geometry-imp-closed-polyline

Polygon

A Polygon is a closed Polyline (implicitely or explicitely) for which we also consider the inside to be an actual surface. Thus is provides a bit more functionalities, like computation of the area.

geometry-polygon

LinesSet

A LinesSet is a generic container for multiple lines. The lines have no specific relation to each other. Due to its implementation, a LinesSet can contain only a single type of lines. If you need to store Polylines of different types, use a MixedLinesSet instead. This should be preferred for new developments, as it allows for more flexibility.

geometry-linesset

Shape

A Shape is a specific kind of LinesSet containing one or more Polygon objects. Some of them are considered to be external outlines, and other as holes, so you can define a very complex surface. Note that by convention, ClipperLib identifies outlines as being oriented counter-clockwise and holes clockwise. Holes will also return a negative area. In the example above, the polygon would actually be a hole.

geometry-shape

SingleShape

A SingleShape is a shape containing a single outline polygon, which may have holes. Note that this is not ensured programmatically, so it is technically possible to add many outlines in a SingleShape. This type mostly exists as an explicit return type.

geometry-singleshape

MixedLinesSet

A MixedLinesSet can contain various types of Polylines, so it is suitable in many situations. It also differs very much with a LinesSet because it uses shared pointer to store the actual Polylines, so they can be easily used by different objects without copy.

geometry-mixedlinesset