HighMap library (C++)
Loading...
Searching...
No Matches
hmap::Point Class Reference

A class to represent and manipulate 2D points that can carry a value. More...

#include <point.hpp>

Public Member Functions

constexpr Point () noexcept
 Default constructor initializing the point to (0, 0, 0).
constexpr Point (float x, float y, float v=0.f) noexcept
 Parameterized constructor initializing the point to given values.
constexpr Point (const glm::vec2 &xy, float v=0.f) noexcept
 Constructs a Point from a glm::vec2 and an optional value.
constexpr Point (const glm::vec3 &xyv) noexcept
 Constructs a Point from a glm::vec3 (x, y, v).
constexpr glm::vec2 to_vec2 () const noexcept
 Converts the point's coordinates to glm::vec2.
constexpr glm::vec3 to_vec3 () const noexcept
 Converts the point's coordinates and value to glm::vec3.
constexpr bool operator== (const Point &other) const noexcept
 Equality operator to check if two points are the same.
constexpr bool operator!= (const Point &other) const noexcept
 Inequality operator to check if two points are different.
constexpr Point operator+ (const Point &other) const noexcept
 Adds two points.
constexpr Point operator- (const Point &other) const noexcept
 Subtracts two points.
constexpr Point operator* (float scalar) const noexcept
 Multiplies the point by a scalar.
constexpr Point operator/ (float scalar) const noexcept
 Divides the point by a scalar.
constexpr Point & operator+= (const Point &other) noexcept
 Adds another point to this point in-place.
constexpr Point & operator-= (const Point &other) noexcept
 Subtracts another point from this point in-place.
constexpr Point & operator*= (float scalar) noexcept
 Multiplies this point by a scalar in-place.
constexpr Point & operator/= (float scalar) noexcept
 Divides this point by a scalar in-place.
void print () const
 Prints the coordinates and value of the Point object.
void set_value_from_array (const Array &array, const BBox2D &bbox)
 Updates the point's value based on bilinear interpolation from an array.

Public Attributes

float x
 The x-coordinate of the point.
float y
 The y-coordinate of the point.
float v
 The value at the point.

Friends

constexpr Point operator* (float scalar, const Point &point) noexcept
 Scalar multiplication (scalar * Point).

Detailed Description

A class to represent and manipulate 2D points that can carry a value.

See unit tests: test_point.cpp

Constructor & Destructor Documentation

◆ Point() [1/4]

hmap::Point::Point ( )
inlineconstexprnoexcept

Default constructor initializing the point to (0, 0, 0).

◆ Point() [2/4]

hmap::Point::Point ( float x,
float y,
float v = 0.f )
inlineconstexprnoexcept

Parameterized constructor initializing the point to given values.

Parameters
xThe x-coordinate of the point.
yThe y-coordinate of the point.
vThe value at the point.

◆ Point() [3/4]

hmap::Point::Point ( const glm::vec2 & xy,
float v = 0.f )
inlineexplicitconstexprnoexcept

Constructs a Point from a glm::vec2 and an optional value.

Parameters
xy2D coordinate vector.
vThe value at the point.

◆ Point() [4/4]

hmap::Point::Point ( const glm::vec3 & xyv)
inlineexplicitconstexprnoexcept

Constructs a Point from a glm::vec3 (x, y, v).

Parameters
xyv3D vector containing (x, y, v).

Member Function Documentation

◆ to_vec2()

glm::vec2 hmap::Point::to_vec2 ( ) const
inlineconstexprnoexcept

Converts the point's coordinates to glm::vec2.

Returns
glm::vec2 The (x, y) coordinates.

◆ to_vec3()

glm::vec3 hmap::Point::to_vec3 ( ) const
inlineconstexprnoexcept

Converts the point's coordinates and value to glm::vec3.

Returns
glm::vec3 The (x, y, v) components.

◆ operator==()

bool hmap::Point::operator== ( const Point & other) const
inlineconstexprnoexcept

Equality operator to check if two points are the same.

Parameters
otherThe point to compare with.
Returns
true if the points are equal, false otherwise.

◆ operator!=()

bool hmap::Point::operator!= ( const Point & other) const
inlineconstexprnoexcept

Inequality operator to check if two points are different.

Parameters
otherThe point to compare with.
Returns
true if the points are not equal, false otherwise.

◆ operator+()

Point hmap::Point::operator+ ( const Point & other) const
inlineconstexprnoexcept

Adds two points.

Parameters
otherThe point to add.
Returns
The result of adding the two points.

◆ operator-()

Point hmap::Point::operator- ( const Point & other) const
inlineconstexprnoexcept

Subtracts two points.

Parameters
otherThe point to subtract.
Returns
The result of subtracting the other point from this point.

◆ operator*()

Point hmap::Point::operator* ( float scalar) const
inlineconstexprnoexcept

Multiplies the point by a scalar.

Parameters
scalarThe scalar to multiply by.
Returns
The result of the multiplication.

◆ operator/()

Point hmap::Point::operator/ ( float scalar) const
inlineconstexprnoexcept

Divides the point by a scalar.

Parameters
scalarThe scalar to divide by.
Returns
The result of the division.

◆ operator+=()

Point & hmap::Point::operator+= ( const Point & other)
inlineconstexprnoexcept

Adds another point to this point in-place.

Parameters
otherThe point to add.
Returns
Reference to this point.

◆ operator-=()

Point & hmap::Point::operator-= ( const Point & other)
inlineconstexprnoexcept

Subtracts another point from this point in-place.

Parameters
otherThe point to subtract.
Returns
Reference to this point.

◆ operator*=()

Point & hmap::Point::operator*= ( float scalar)
inlineconstexprnoexcept

Multiplies this point by a scalar in-place.

Parameters
scalarThe scalar multiplier.
Returns
Reference to this point.

◆ operator/=()

Point & hmap::Point::operator/= ( float scalar)
inlineconstexprnoexcept

Divides this point by a scalar in-place.

Parameters
scalarThe scalar divisor.
Returns
Reference to this point.

◆ print()

void hmap::Point::print ( ) const

Prints the coordinates and value of the Point object.

This function outputs the Point's x, y coordinates, and value v to stdout in the format (x, y, v), followed by a newline.

◆ set_value_from_array()

void hmap::Point::set_value_from_array ( const Array & array,
const BBox2D & bbox )

Updates the point's value based on bilinear interpolation from an array.

Parameters
arrayThe input Array from which the value is interpolated.
bboxBounding box used for normalizing coordinates {xmin, xmax, ymin, ymax}.

◆ operator*

Point operator* ( float scalar,
const Point & point )
friend

Scalar multiplication (scalar * Point).

Parameters
scalarThe scalar value to multiply with.
pointThe point to multiply.
Returns
Point A new point with each component multiplied by scalar.

Member Data Documentation

◆ x

float hmap::Point::x

The x-coordinate of the point.

◆ y

float hmap::Point::y

The y-coordinate of the point.

◆ v

float hmap::Point::v

The value at the point.


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