mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added some nodiscards
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
//
|
||||
|
||||
#include "uml/Vector4.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace uml
|
||||
@@ -81,39 +83,48 @@ namespace uml
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector4& Vector4::Clamp(const float min, const float max)
|
||||
{
|
||||
x = std::clamp(x, min, max);
|
||||
y = std::clamp(y, min, max);
|
||||
z = std::clamp(z, min, max);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator-() const
|
||||
{
|
||||
return Vector4(-x, -y, -z, -w);
|
||||
return {-x, -y, -z, -w};
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator+(const Vector4& v) const
|
||||
{
|
||||
return Vector4(x + v.x, y + v.y, z + v.z, w + v.w);
|
||||
return {x + v.x, y + v.y, z + v.z, w + v.w};
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator-(const Vector4& v) const
|
||||
{
|
||||
return Vector4(x - v.x, y - v.y, z - v.z, w - v.w);
|
||||
return {x - v.x, y - v.y, z - v.z, w - v.w};
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator*(float scalar) const
|
||||
{
|
||||
return Vector4(x * scalar, y * scalar, z * scalar, w * scalar);
|
||||
return {x * scalar, y * scalar, z * scalar, w * scalar};
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator*(const Vector4& v) const
|
||||
{
|
||||
return Vector4(x * v.x, y * v.y, z * v.z, w * v.w);
|
||||
return {x * v.x, y * v.y, z * v.z, w * v.w};
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator/(float scalar) const
|
||||
{
|
||||
return Vector4(x / scalar, y / scalar, z / scalar, w / scalar);
|
||||
return {x / scalar, y / scalar, z / scalar, w / scalar};
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator/(const Vector4& v) const
|
||||
{
|
||||
return Vector4(x / v.x, y / v.y, z / v.z, w / v.w);
|
||||
return {x / v.x, y / v.y, z / v.z, w / v.w};
|
||||
}
|
||||
|
||||
float Vector4::Sum() const
|
||||
|
||||
@@ -17,20 +17,22 @@ namespace uml::color
|
||||
return Color( (*this * (1.f - ratio)) + (other * ratio) );
|
||||
}
|
||||
|
||||
Color::Color(float r, float g, float b, float a) : Vector4(r,g,b,a)
|
||||
Color::Color(const float r, const float g, const float b, const float a)
|
||||
: Vector4(std::clamp(r, 0.f, 1.f),
|
||||
std::clamp(g, 0.f, 1.f),
|
||||
std::clamp(b, 0.f, 1.f),
|
||||
std::clamp(a, 0.f, 1.f))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Color::Color(const Vector4 &vec) : Vector4(vec)
|
||||
Color::Color(Vector4 vec) : Vector4(vec.Clamp(0.f, 1.f))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Color Color::FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
|
||||
{
|
||||
|
||||
return Color{Vector4(r, g, b, a) / 255.f};
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user