/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#pragma once
#include
struct CSMap {};
struct CSProjected {};
template
struct Vec2
{
public:
Vec2() = default;
Vec2(T x_, T y_) : x(x_), y(y_) {}
bool operator==(const Vec2& other) const = default;
inline Vec2& operator +=(const Vec2& other) {
x += other.x;
y += other.y;
return *this;
}
inline Vec2& operator -=(const Vec2& other) {
x -= other.x;
y -= other.y;
return *this;
}
inline Vec2& operator *=(const T v)
{
x *= v;
y *= v;
return *this;
}
inline Vec2& operator *=(const Vec2& other)
{
x *= other.x;
y *= other.y;
return *this;
}
inline Vec2& operator /=(const Vec2& other)
{
x /= other.x;
y /= other.y;
return *this;
}
inline Vec2& operator /=(const T v)
{
x /= v;
y /= v;
return *this;
}
void set(const T x_, const T y_)
{
x = x_;
y = y_;
}
template
inline Vec2 convertT() const
{
return Vec2(static_cast(x), static_cast(y));
}
inline Vec2 inverted() const
{
return Vec2(1.0f / static_cast(x), 1.0f / static_cast(y));
}
inline Vec2 negated() const
{
return Vec2(-x, -y);
}
public:
T x = 0;
T y = 0;
};
template
inline Vec2 operator+(const Vec2& l, const Vec2& r)
{
auto res = l;
res += r;
return res;
}
template
inline Vec2 operator-(const Vec2& l, const Vec2& r)
{
auto res = l;
res -= r;
return res;
}
template
inline Vec2 operator*(const Vec2& l, const Vec2& r)
{
auto res = l;
res *= r;
return res;
}
template
inline Vec2 operator*(const Vec2& l, const Vec2& r)
{
return Vec2(l.x * r.x, l.y * r.y);
}
template
inline Vec2 operator*(const Vec2& l, const T r)
{
auto res = l;
res *= r;
return res;
}
template
inline Vec2 operator/(const Vec2& l, const Vec2& r)
{
auto res = l;
res /= r;
return res;
}
template
inline Vec2 operator/(const Vec2& l, const Vec2& r)
{
return Vec2(l.x / r.x, l.y / r.y);
}
template
inline Vec2 operator/(const Vec2& l, const T r)
{
auto res = l;
res /= r;
return res;
}
template
struct Coords2
{
Coords2() = default;
Coords2(T x_, T y_) : x(x_), y(y_) {}
bool operator==(const Coords2& other) const = default;
T x = 0;
T y = 0;
Coords2& operator +=(const Vec2& other) {
x += other.x;
y += other.y;
return *this;
}
Coords2& operator -=(const Vec2& other) {
x -= other.x;
y -= other.y;
return *this;
}
void set(const T x_, const T y_)
{
x = x_;
y = y_;
}
template
inline Coords2 convertT() const
{
return Coords2(static_cast(x), static_cast(y));
}
};
template
inline Coords2 operator+(const Coords2& l, const Vec2& r)
{
auto res = l;
res += r;
return res;
}
template
inline Coords2 operator-(const Coords2& l, const Vec2& r)
{
auto res = l;
res -= r;
return res;
}
template
inline Vec2 operator-(const Coords2& l, const Coords2& r)
{
return Vec2(l.x - r.x, l.y - r.y);
}
template
inline Coords2 operator*(const Coords2& l, const Vec2& r)
{
return Coords2(l.x * r.x, l.y * r.y);
}
template
inline Coords2 operator*(const Coords2& l, const Vec2& r)
{
return Coords2(l.x * r.x, l.y * r.y);
}
template
inline Coords2 operator/(const Coords2& l, const Vec2& r)
{
return Coords2(l.x / r.x, l.y / r.y);
}
typedef Vec2 MapVec;
///
/// Logical map coordinates in tiles
///
typedef Coords2 MapCoords;
typedef Vec2 ProjectedVec;
typedef Coords2 ProjectedCoords;