struct mrpt::math::TObject2D

A variant type for any lightweight 2D type: point, segment, line, polygon.

Use provided helper method, or directly access the variant data.

See also:

TPoint2D, TSegment2D, TLine2D, TPolygon2D

#include <mrpt/math/TObject2D.h>

struct TObject2D
{
    // typedefs

    typedef std::variant<std::monostate, TPoint2D, TSegment2D, TLine2D, TPolygon2D> variant_t;

    //
fields

    variant_t data;

    // construction

    TObject2D();

    //
methods

    bool isPoint() const;
    bool isSegment() const;
    bool isLine() const;
    bool isPolygon() const;
    bool empty() const;

    template <typename T>
    const T& getAs() const;

    template <typename T>
    T& getAs();

    bool getPoint(TPoint2D& out) const;
    bool getSegment(TSegment2D& out) const;
    bool getLine(TLine2D& out) const;
    bool getPolygon(TPolygon2D& out) const;
    std::string asString() const;
    TObject3D generate3DObject() const;

    template <typename T>
    static TObject2D From(const T& p);
};

Methods

bool isPoint() const

Checks whether content is a point.

bool isSegment() const

Checks whether content is a segment.

bool isLine() const

Checks whether content is a line.

bool isPolygon() const

Checks whether content is a polygon.

template <typename T>
const T& getAs() const

Gets the content as a given expected type (an exception will be thrown if type is wrong, check type first).

template <typename T>
T& getAs()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool getPoint(TPoint2D& out) const

returns true if the objects is a point, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

bool getSegment(TSegment2D& out) const

returns true if the objects is a segment, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

bool getLine(TLine2D& out) const

returns true if the objects is a line, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

bool getPolygon(TPolygon2D& out) const

returns true if the objects is a TPolygon2D, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

std::string asString() const

Gets a string with the type and the parameters of the object.

empty if not defined. New in MRPT 2.3.0

TObject3D generate3DObject() const

Cast into 3D space.

template <typename T>
static TObject2D From(const T& p)

Constructor from point, segment, line, polygon.