30#include "utility/math/vector.hpp"
32namespace utility::graphic
39 template<
typename Type>
54 template<CanBeScaleComponent ScaleComponentType>
class Scale:
62 : math::
Vector<ScaleComponentType, 3>(
63 { ScaleComponentType { 1.0f }, ScaleComponentType { 1.0f },
64 ScaleComponentType { 1.0f } })
74 explicit Scale(ScaleComponentType value)
75 : math::
Vector<ScaleComponentType, 3>({ value, value, value })
95 Scale(ScaleComponentType x, ScaleComponentType y, ScaleComponentType z)
96 : math::
Vector<ScaleComponentType, 3>({ x, y, z })
106 Scale(std::initializer_list<ScaleComponentType> values)
107 : math::
Vector<ScaleComponentType, 3>(
108 { ScaleComponentType { 1.0f }, ScaleComponentType { 1.0f },
109 ScaleComponentType { 1.0f } })
111 if (values.size() != 3) {
112 throw std::invalid_argument(
113 "Scale requires exactly three components");
115 const auto it = values.begin();
125 Scale(
const std::initializer_list<ScaleComponentType> &value)
126 : math::
Vector<ScaleComponentType, 3>(value)
176 ScaleComponentType
getX(
void)
const noexcept
196 ScaleComponentType
getY(
void)
const noexcept
216 ScaleComponentType
getZ(
void)
const noexcept
266 bool isUniform(ScaleComponentType epsilon = ScaleComponentType {
267 1e-6 })
const noexcept
269 return std::abs(this->x - this->y) <= epsilon
270 && std::abs(this->y - this->z) <= epsilon;
279 return this->x < ScaleComponentType {}
280 || this->y < ScaleComponentType {}
281 || this->z < ScaleComponentType {};
291 if (this->x != other.x) {
294 if (this->y != other.y) {
297 if (this->z != other.z) {
310 return !(*
this == other);
320 if (this->x != other.x) {
321 return this->x < other.x;
323 if (this->y != other.y) {
324 return this->y < other.y;
326 if (this->z != other.z) {
327 return this->z < other.z;
336 using ScaleF = Scale<float>;
341 using ScaleD = Scale<double>;
349 std::ostream &operator<<(std::ostream &stream,
const ScaleF &scale);
357 std::ostream &operator<<(std::ostream &stream,
const ScaleD &scale);
Scale in 3D space represented as a vector of three ScaleComponentType components (x,...
Scale(const Scale &other)=default
Copy constructor.
Scale(std::initializer_list< ScaleComponentType > values)
Construct from initializer list of three ScaleComponentType values.
Scale & scaleBy(const Scale &factor) noexcept
Scale this object by another scale (component-wise multiplication).
Scale(ScaleComponentType value)
Construct by filling all components with the same ScaleComponentType value.
Scale & operator=(const Scale &other)=default
Copy assignment operator.
ScaleComponentType getZ(void) const noexcept
Get the Z component of the scale.
Scale(void)
Default constructor initializing scale to (1, 1, 1).
Scale(Scale &&other) noexcept=default
Move constructor.
Scale(ScaleComponentType x, ScaleComponentType y, ScaleComponentType z)
Construct from three ScaleComponentType values (x, y, z).
Scale & setUniform(ScaleComponentType value) noexcept
Set all scale components to the same value.
Scale & setX(const ScaleComponentType value) noexcept
Set the X component of the scale.
Scale & operator=(Scale &&other) noexcept=default
Move assignment operator.
~Scale(void)=default
Default destructor for Scale.
Scale & setZ(const ScaleComponentType value) noexcept
Set the Z component of the scale.
Scale(const std::initializer_list< ScaleComponentType > &value)
Construct from a GLM vector.
Scale scaled(const Scale &factor) const noexcept
Return a scaled copy of this object (component-wise multiplication).
ScaleComponentType getY(void) const noexcept
Get the Y component of the scale.
Scale & setY(const ScaleComponentType value) noexcept
Set the Y component of the scale.
bool operator==(const Scale &other) const noexcept
Equality comparison.
Scale(const utility::math::Vector< ScaleComponentType, 3 > &vector)
Construct from a vector.
bool operator<(const Scale &other) const noexcept
Less-than comparison for ordering.
bool operator!=(const Scale &other) const noexcept
Inequality comparison.
ScaleComponentType getX(void) const noexcept
Get the X component of the scale.
bool isUniform(ScaleComponentType epsilon=ScaleComponentType { 1e-6 }) const noexcept
Check whether all scale components are approximately equal.
bool hasNegativeComponent(void) const noexcept
Check whether any component is negative.
3D vector class inheriting from glm::vec3.
Vector(void)
Default constructor initializing vector values to zero.
Concept to constrain scale component type.
Concept to constrain vector component type.
The utility namespace contains classes and functions for the utility project.