summaryrefslogtreecommitdiff
path: root/src/helpers/Vector2D.hpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-06-19 16:20:06 +0200
committerVaxry <vaxry@vaxry.net>2024-06-19 16:20:15 +0200
commitfb15b7aa2a9bba0f0693f84d0c65d386942583f8 (patch)
treed4403944b5d6a3e03d2262f03a7d0b3ed6ffae24 /src/helpers/Vector2D.hpp
parent6e5804b53de753f24953d9d647940df66bc68f6d (diff)
core: Move to hyprutils for Math
Moves CRegion, CBox and Vector2D over to hyprutils. Requires hyprutils>=0.1.4
Diffstat (limited to 'src/helpers/Vector2D.hpp')
-rw-r--r--src/helpers/Vector2D.hpp133
1 files changed, 0 insertions, 133 deletions
diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp
deleted file mode 100644
index 0f1440c3..00000000
--- a/src/helpers/Vector2D.hpp
+++ /dev/null
@@ -1,133 +0,0 @@
-#pragma once
-
-#include <cmath>
-#include <format>
-#include "../macros.hpp"
-#include <hyprlang.hpp>
-
-class Vector2D {
- public:
- Vector2D(double, double);
- Vector2D();
- ~Vector2D();
- Vector2D(const Hyprlang::VEC2&);
-
- double x = 0;
- double y = 0;
-
- // returns the scale
- double normalize();
-
- Vector2D operator+(const Vector2D& a) const {
- return Vector2D(this->x + a.x, this->y + a.y);
- }
- Vector2D operator-(const Vector2D& a) const {
- return Vector2D(this->x - a.x, this->y - a.y);
- }
- Vector2D operator-() const {
- return Vector2D(-this->x, -this->y);
- }
- Vector2D operator*(const double& a) const {
- return Vector2D(this->x * a, this->y * a);
- }
- Vector2D operator/(const double& a) const {
- return Vector2D(this->x / a, this->y / a);
- }
-
- bool operator==(const Vector2D& a) const {
- return a.x == x && a.y == y;
- }
-
- bool operator!=(const Vector2D& a) const {
- return a.x != x || a.y != y;
- }
-
- Vector2D operator*(const Vector2D& a) const {
- return Vector2D(this->x * a.x, this->y * a.y);
- }
-
- Vector2D operator/(const Vector2D& a) const {
- return Vector2D(this->x / a.x, this->y / a.y);
- }
-
- bool operator>(const Vector2D& a) const {
- return this->x > a.x && this->y > a.y;
- }
-
- bool operator<(const Vector2D& a) const {
- return this->x < a.x && this->y < a.y;
- }
- Vector2D& operator+=(const Vector2D& a) {
- this->x += a.x;
- this->y += a.y;
- return *this;
- }
- Vector2D& operator-=(const Vector2D& a) {
- this->x -= a.x;
- this->y -= a.y;
- return *this;
- }
- Vector2D& operator*=(const Vector2D& a) {
- this->x *= a.x;
- this->y *= a.y;
- return *this;
- }
- Vector2D& operator/=(const Vector2D& a) {
- this->x /= a.x;
- this->y /= a.y;
- return *this;
- }
- Vector2D& operator*=(const double& a) {
- this->x *= a;
- this->y *= a;
- return *this;
- }
- Vector2D& operator/=(const double& a) {
- this->x /= a;
- this->y /= a;
- return *this;
- }
-
- double distance(const Vector2D& other) const;
- double distanceSq(const Vector2D& other) const;
- double size() const;
- Vector2D clamp(const Vector2D& min, const Vector2D& max = Vector2D{-1, -1}) const;
-
- Vector2D floor() const;
- Vector2D round() const;
-
- Vector2D getComponentMax(const Vector2D& other) const;
-};
-
-/**
- format specification
- - 'j', as json array
- - 'X', same as std::format("{}x{}", vec.x, vec.y)
- - number, floating point precision, use `0` to format as integer
-*/
-template <typename CharT>
-struct std::formatter<Vector2D, CharT> : std::formatter<CharT> {
- bool formatJson = false;
- bool formatX = false;
- std::string precision = "";
- FORMAT_PARSE(FORMAT_FLAG('j', formatJson) //
- FORMAT_FLAG('X', formatX) //
- FORMAT_NUMBER(precision),
- Vector2D)
-
- template <typename FormatContext>
- auto format(const Vector2D& vec, FormatContext& ctx) const {
- std::string formatString = precision.empty() ? "{}" : std::format("{{:.{}f}}", precision);
-
- if (formatJson)
- formatString = std::format("[{0}, {0}]", formatString);
- else if (formatX)
- formatString = std::format("{0}x{0}", formatString);
- else
- formatString = std::format("[Vector2D: x: {0}, y: {0}]", formatString);
- try {
- string buf = std::vformat(formatString, std::make_format_args(vec.x, vec.y));
- return std::format_to(ctx.out(), "{}", buf);
- } catch (std::format_error& e) { return std::format_to(ctx.out(), "[{}, {}]", vec.x, vec.y); }
- }
-};