From 620954631a0a45ec41b8942e1f49617d4160de32 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Tue, 2 Jul 2024 07:36:21 +0200 Subject: [PATCH] Add math ops --- src/text_editor/rect2.cpp | 65 ++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/src/text_editor/rect2.cpp b/src/text_editor/rect2.cpp index ad3650e..4e18233 100644 --- a/src/text_editor/rect2.cpp +++ b/src/text_editor/rect2.cpp @@ -72,23 +72,52 @@ Rect2 CutTop(Rect2 *r, float value) { return result; } -Rect2 operator-(Rect2 r, float value) { - r.min.x -= value; - r.min.y -= value; - r.max.x -= value; - r.max.y -= value; - return r; -} +// clang-format off +Rect2 operator-(Rect2 r, Rect2 value) { return { r.min.x - value.min.x, r.min.y - value.min.y, r.max.x - value.max.x, r.max.y - value.max.y }; } +Rect2 operator+(Rect2 r, Rect2 value) { return { r.min.x + value.min.x, r.min.y + value.min.y, r.max.x + value.max.x, r.max.y + value.max.y }; } +Rect2 operator*(Rect2 r, Rect2 value) { return { r.min.x * value.min.x, r.min.y * value.min.y, r.max.x * value.max.x, r.max.y * value.max.y }; } +Rect2 operator/(Rect2 r, Rect2 value) { return { r.min.x / value.min.x, r.min.y / value.min.y, r.max.x / value.max.x, r.max.y / value.max.y }; } -Rect2 operator-(Rect2 r, Vec2 value) { - r.min.x -= value.x; - r.min.y -= value.y; - r.max.x -= value.x; - r.max.y -= value.y; - return r; -} +Rect2 operator-(Rect2 r, Vec2 value) { return { r.min.x - value.x, r.min.y - value.y, r.max.x - value.x, r.max.y - value.y }; } +Rect2 operator+(Rect2 r, Vec2 value) { return { r.min.x + value.x, r.min.y + value.y, r.max.x + value.x, r.max.y + value.y }; } +Rect2 operator*(Rect2 r, Vec2 value) { return { r.min.x * value.x, r.min.y * value.y, r.max.x * value.x, r.max.y * value.y }; } +Rect2 operator/(Rect2 r, Vec2 value) { return { r.min.x / value.x, r.min.y / value.y, r.max.x / value.x, r.max.y / value.y }; } -Rect2 operator-=(Rect2 &r, Vec2 value) { - r = r - value; - return r; -} \ No newline at end of file +Rect2 operator-(Rect2 r, float value) { return { r.min.x - value, r.min.y - value, r.max.x - value, r.max.y - value }; } +Rect2 operator+(Rect2 r, float value) { return { r.min.x + value, r.min.y + value, r.max.x + value, r.max.y + value }; } +Rect2 operator*(Rect2 r, float value) { return { r.min.x * value, r.min.y * value, r.max.x * value, r.max.y * value }; } +Rect2 operator/(Rect2 r, float value) { return { r.min.x / value, r.min.y / value, r.max.x / value, r.max.y / value }; } + +Rect2 operator-=(Rect2 &r, Rect2 value) { r = r - value; return r; } +Rect2 operator+=(Rect2 &r, Rect2 value) { r = r + value; return r; } +Rect2 operator*=(Rect2 &r, Rect2 value) { r = r * value; return r; } +Rect2 operator/=(Rect2 &r, Rect2 value) { r = r / value; return r; } +Rect2 operator-=(Rect2 &r, Vec2 value) { r = r - value; return r; } +Rect2 operator+=(Rect2 &r, Vec2 value) { r = r + value; return r; } +Rect2 operator*=(Rect2 &r, Vec2 value) { r = r * value; return r; } +Rect2 operator/=(Rect2 &r, Vec2 value) { r = r / value; return r; } +Rect2 operator-=(Rect2 &r, float value) { r = r - value; return r; } +Rect2 operator+=(Rect2 &r, float value) { r = r + value; return r; } +Rect2 operator*=(Rect2 &r, float value) { r = r * value; return r; } +Rect2 operator/=(Rect2 &r, float value) { r = r / value; return r; } + +Vec2 operator-(Vec2 a, Vec2 b) { return {a.x - b.x, a.y - b.y}; } +Vec2 operator+(Vec2 a, Vec2 b) { return {a.x + b.x, a.y + b.y}; } +Vec2 operator*(Vec2 a, Vec2 b) { return {a.x * b.x, a.y * b.y}; } +Vec2 operator/(Vec2 a, Vec2 b) { return {a.x / b.x, a.y / b.y}; } + +Vec2 operator-(Vec2 a, float b) { return {a.x - b, a.y - b}; } +Vec2 operator+(Vec2 a, float b) { return {a.x + b, a.y + b}; } +Vec2 operator*(Vec2 a, float b) { return {a.x * b, a.y * b}; } +Vec2 operator/(Vec2 a, float b) { return {a.x / b, a.y / b}; } + +Vec2 operator-=(Vec2 &a, Vec2 b) { a = a - b; return a; } +Vec2 operator+=(Vec2 &a, Vec2 b) { a = a + b; return a; } +Vec2 operator*=(Vec2 &a, Vec2 b) { a = a * b; return a; } +Vec2 operator/=(Vec2 &a, Vec2 b) { a = a / b; return a; } +Vec2 operator-=(Vec2 &a, float b) { a = a - b; return a; } +Vec2 operator+=(Vec2 &a, float b) { a = a + b; return a; } +Vec2 operator*=(Vec2 &a, float b) { a = a * b; return a; } +Vec2 operator/=(Vec2 &a, float b) { a = a / b; return a; } + +// clang-format on