CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::Point Class Reference

Integer 3D point with an optional attached Size; interoperates with PointFloat and vectors. More...

#include <MathClasses.h>

Collaboration diagram for cmlabs::Point:
[legend]

Public Member Functions

 Point ()
 Origin (0,0,0).
 Point (int px, int py, int pz=0, Size psize=Size())
 From coordinates and optional size.
virtual ~Point ()
 operator PointFloat () const
 Implicit conversion to the floating-point variant.
int operator[] (int n) const
 Component access: 0=x, 1=y, 2=z.
bool operator== (const Point &p) const
 Exact coordinate equality.
bool operator== (const PointFloat &p) const
 Equality against a float point.
Point operator- (const Point &p) const
 Element-wise difference.
PointFloat operator- (const PointFloat &p) const
 Difference, promoted to float.
Point operator+ (const Point &p) const
 Element-wise sum.
PointFloat operator+ (const PointFloat &p) const
 Sum, promoted to float.
PointFloat operator+ (const Vector2D &v) const
 Translate by a 2D vector.
PointFloat operator+ (const Vector3D &v) const
 Translate by a 3D vector.
Point operator* (const Point &p) const
 Element-wise product.
PointFloat operator* (const PointFloat &p) const
 Element-wise product, promoted to float.
Point operator- (double a) const
 Subtract scalar from each coordinate.
Point operator+ (double a) const
 Add scalar to each coordinate.
Point operator* (double a) const
 Scale each coordinate.
int getX () const
int getY () const
int getZ () const
Size getSize () const
bool set (int x, int y, int z=0)
 Set all coordinates.
bool setX (int n)
 Set x.
bool setY (int n)
 Set y.
bool setZ (int n)
 Set z.
bool setSize (Size s)
 Set the attached size.
double getDistanceTo (Point &p) const
 Euclidean distance to another point.
double getDistanceTo (PointFloat &p) const
 Euclidean distance to a float point.
std::string print ()
 Human-readable representation for debugging.

Public Attributes

int x
int y
int z
Size size

Detailed Description

Integer 3D point with an optional attached Size; interoperates with PointFloat and vectors.

Arithmetic operators are element-wise; operator[] indexes x=0, y=1, z=2. Mixed Point/PointFloat arithmetic promotes to PointFloat; converting a PointFloat back to Point truncates (does not round) each coordinate. The attached Size lets a point double as "position + extent" (e.g. a detection center with its bounding size) without a separate Box.

using namespace cmlabs;
Point p(10, 20);
PointFloat q(10.5, 19.25);
PointFloat d = q - p; // element-wise, promoted to float
double dist = p.getDistanceTo(q); // Euclidean distance
Point r = (Point)q; // truncates to (10, 19)
Floating-point 3D point with an optional attached Size; float counterpart of Point.
double getDistanceTo(const Point &p) const
Euclidean distance to an integer point.
Point()
Origin (0,0,0).

Definition at line 385 of file MathClasses.h.

Constructor & Destructor Documentation

◆ Point() [1/2]

cmlabs::Point::Point ( )

Origin (0,0,0).

Definition at line 67 of file MathClasses.cpp.

References x, y, and z.

Referenced by getDistanceTo(), operator*(), operator*(), operator+(), operator+(), operator-(), operator-(), and operator==().

◆ Point() [2/2]

cmlabs::Point::Point ( int px,
int py,
int pz = 0,
Size psize = Size() )

From coordinates and optional size.

Definition at line 68 of file MathClasses.cpp.

References size, x, y, and z.

◆ ~Point()

cmlabs::Point::~Point ( )
virtual

Definition at line 69 of file MathClasses.cpp.

Member Function Documentation

◆ getDistanceTo() [1/2]

double cmlabs::Point::getDistanceTo ( Point & p) const

Euclidean distance to another point.

Definition at line 197 of file MathClasses.cpp.

References getX(), getY(), and Point().

Referenced by cmlabs::MathClasses_UnitTest().

◆ getDistanceTo() [2/2]

double cmlabs::Point::getDistanceTo ( PointFloat & p) const

Euclidean distance to a float point.

Definition at line 200 of file MathClasses.cpp.

References getX(), cmlabs::PointFloat::getX(), getY(), and cmlabs::PointFloat::getY().

◆ getSize()

Size cmlabs::Point::getSize ( ) const
Returns
Attached size.

Definition at line 189 of file MathClasses.cpp.

References size.

◆ getX()

int cmlabs::Point::getX ( ) const
Returns
x.

Definition at line 186 of file MathClasses.cpp.

References x.

Referenced by getDistanceTo(), getDistanceTo(), cmlabs::PointFloat::getDistanceTo(), and cmlabs::MathClasses_UnitTest().

◆ getY()

int cmlabs::Point::getY ( ) const
Returns
y.

Definition at line 187 of file MathClasses.cpp.

References y.

Referenced by getDistanceTo(), getDistanceTo(), and cmlabs::MathClasses_UnitTest().

◆ getZ()

int cmlabs::Point::getZ ( ) const
Returns
z.

Definition at line 188 of file MathClasses.cpp.

References z.

◆ operator PointFloat()

cmlabs::Point::operator PointFloat ( ) const

Implicit conversion to the floating-point variant.

Definition at line 71 of file MathClasses.cpp.

References cmlabs::PointFloat::setSize(), cmlabs::PointFloat::setX(), cmlabs::PointFloat::setY(), cmlabs::PointFloat::setZ(), size, x, y, and z.

◆ operator*() [1/3]

Point cmlabs::Point::operator* ( const Point & p) const

Element-wise product.

Definition at line 149 of file MathClasses.cpp.

References Point(), x, y, and z.

◆ operator*() [2/3]

PointFloat cmlabs::Point::operator* ( const PointFloat & p) const

Element-wise product, promoted to float.

Definition at line 156 of file MathClasses.cpp.

References cmlabs::PointFloat::x, cmlabs::PointFloat::y, and cmlabs::PointFloat::z.

◆ operator*() [3/3]

Point cmlabs::Point::operator* ( double a) const

Scale each coordinate.

Definition at line 177 of file MathClasses.cpp.

References Point(), x, y, and z.

◆ operator+() [1/5]

Point cmlabs::Point::operator+ ( const Point & p) const

Element-wise sum.

Definition at line 122 of file MathClasses.cpp.

References Point(), x, y, and z.

◆ operator+() [2/5]

PointFloat cmlabs::Point::operator+ ( const PointFloat & p) const

Sum, promoted to float.

Definition at line 129 of file MathClasses.cpp.

References cmlabs::PointFloat::x, cmlabs::PointFloat::y, and cmlabs::PointFloat::z.

◆ operator+() [3/5]

PointFloat cmlabs::Point::operator+ ( const Vector2D & v) const

Translate by a 2D vector.

Definition at line 136 of file MathClasses.cpp.

References cmlabs::PointFloat::x, cmlabs::Vector2D::x, cmlabs::PointFloat::y, and cmlabs::Vector2D::y.

◆ operator+() [4/5]

PointFloat cmlabs::Point::operator+ ( const Vector3D & v) const

◆ operator+() [5/5]

Point cmlabs::Point::operator+ ( double a) const

Add scalar to each coordinate.

Definition at line 170 of file MathClasses.cpp.

References Point(), x, y, and z.

◆ operator-() [1/3]

Point cmlabs::Point::operator- ( const Point & p) const

Element-wise difference.

Definition at line 108 of file MathClasses.cpp.

References Point(), x, y, and z.

◆ operator-() [2/3]

PointFloat cmlabs::Point::operator- ( const PointFloat & p) const

Difference, promoted to float.

Definition at line 115 of file MathClasses.cpp.

References cmlabs::PointFloat::x, cmlabs::PointFloat::y, and cmlabs::PointFloat::z.

◆ operator-() [3/3]

Point cmlabs::Point::operator- ( double a) const

Subtract scalar from each coordinate.

Definition at line 163 of file MathClasses.cpp.

References Point(), x, y, and z.

◆ operator==() [1/2]

bool cmlabs::Point::operator== ( const Point & p) const

Exact coordinate equality.

Definition at line 92 of file MathClasses.cpp.

References Point(), size, x, y, and z.

◆ operator==() [2/2]

bool cmlabs::Point::operator== ( const PointFloat & p) const

Equality against a float point.

Definition at line 100 of file MathClasses.cpp.

References cmlabs::PointFloat::size, x, cmlabs::PointFloat::x, cmlabs::PointFloat::y, and cmlabs::PointFloat::z.

◆ operator[]()

int cmlabs::Point::operator[] ( int n) const

Component access: 0=x, 1=y, 2=z.

Definition at line 80 of file MathClasses.cpp.

References x, y, and z.

◆ print()

std::string cmlabs::Point::print ( )

Human-readable representation for debugging.

Definition at line 204 of file MathClasses.cpp.

References size, cmlabs::utils::StringFormat(), x, y, and z.

◆ set()

bool cmlabs::Point::set ( int x,
int y,
int z = 0 )

Set all coordinates.

Returns
true.

Definition at line 191 of file MathClasses.cpp.

References x, y, and z.

◆ setSize()

bool cmlabs::Point::setSize ( Size s)

Set the attached size.

Returns
true.

Definition at line 195 of file MathClasses.cpp.

References size.

Referenced by cmlabs::PointFloat::operator Point().

◆ setX()

bool cmlabs::Point::setX ( int n)

Set x.

Returns
true.

Definition at line 192 of file MathClasses.cpp.

References x.

Referenced by cmlabs::PointFloat::operator Point().

◆ setY()

bool cmlabs::Point::setY ( int n)

Set y.

Returns
true.

Definition at line 193 of file MathClasses.cpp.

References y.

Referenced by cmlabs::PointFloat::operator Point().

◆ setZ()

bool cmlabs::Point::setZ ( int n)

Set z.

Returns
true.

Definition at line 194 of file MathClasses.cpp.

References z.

Referenced by cmlabs::PointFloat::operator Point().

Member Data Documentation

◆ size

Size cmlabs::Point::size

◆ x

◆ y

◆ z


The documentation for this class was generated from the following files: