Skip to content

Latest commit

 

History

History
88 lines (57 loc) · 2.39 KB

homog2d_Polyline.md

File metadata and controls

88 lines (57 loc) · 2.39 KB

Technical details on the Polyline classes

Manual main page

The two classes, open and closed type, are actually the same class and are defined as:

template<typename T>
using CPolyline_ = base::PolylineBase<typ::IsClosed,T>;
template<typename T>
using OPolyline_ = base::PolylineBase<typ::IsOpen,T>;

Difference between these two types:

Both types can be seen as a container holding a set of points. Order of points will be retained, but some normalizing step may occur, in a way that will be different for the two types:

  • The CPolyline_ type will see its content rotated so that the smallest point is placed in first position, and reversed so that the second smallest point is placed in second position.

  • The OPolyline_ type will get reversed so that the smallest point is placed in first position.

For both types, the normalisation occurs only when needed (on first comparison).

The rationale for that normalization is that we want to be able to detect identical objects. For example, the single-segment Polyline object described by the points (0,0)-(1,1) is obviously the same as the one described by (1,1)-(0,0).

Conversions:

Say we have:

OPolyline po;
CPolyline pc;

This is possible: pc = po;: the first point gets connected to the last one.

This is not possible: po = pc; (build failure), because we would be unable to determine which segment needs to be removed.

Initializing

The default constructors for both types will build an empty object (which is perfectly valid).

Since there is a normalizing step involved, it is not possible for both types to add points "on the fly". You will need to build a vector of points to initialize the Polyline object:

std::vector<Point2d> vec{ {0,0},{1,0},{1,1} };
OPolyline po(vec);
CPolyline pc(vec);

(std::vector is an example but you can use std::array or std::list)

This can be done in a single step:

OPolyline po( std::vector<Point2d>{ {0,0},{1,0},{1,1} } );
CPolyline pc( std::vector<Point2d>{ {0,0},{1,0},{1,1} } );

It is possible to replace all the points of a Polyline by another set of points:

OPolyline po(vec1);
CPolyline pc(vec1);
po.set( vec2 );
pc.set( vec2 );

The minimum size is 2 points, an object of 1 point is not legal. Thus, this will throw:

std::vector<Point2d> vec{ {0,0} };
OPolyline po(vec);
CPolyline pc(vec);