-
-
Notifications
You must be signed in to change notification settings - Fork 879
Geometric Base Types
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
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.
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
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.
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"
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.
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.
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.
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.
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.
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.
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.