mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-11-22 00:48:09 +01:00
Now Vector2i is in it's own header and cpp file.
This commit is contained in:
parent
c726a4b2f1
commit
987f77442a
@ -35,6 +35,7 @@
|
||||
#include "core/math/rect2.h"
|
||||
#include "core/math/triangulate.h"
|
||||
#include "core/math/vector3.h"
|
||||
#include "core/math/vector2i.h"
|
||||
#include "core/object.h"
|
||||
#include "core/pool_vector.h"
|
||||
#include "core/print_string.h"
|
||||
|
@ -31,6 +31,7 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/math/vector2.h" // also includes math_funcs and ustring
|
||||
#include "core/math/vector2i.h"
|
||||
|
||||
struct Transform2D;
|
||||
|
||||
|
@ -199,55 +199,3 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const {
|
||||
return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y);
|
||||
}
|
||||
|
||||
/* Vector2i */
|
||||
|
||||
Vector2i Vector2i::operator+(const Vector2i &p_v) const {
|
||||
return Vector2i(x + p_v.x, y + p_v.y);
|
||||
}
|
||||
void Vector2i::operator+=(const Vector2i &p_v) {
|
||||
x += p_v.x;
|
||||
y += p_v.y;
|
||||
}
|
||||
Vector2i Vector2i::operator-(const Vector2i &p_v) const {
|
||||
return Vector2i(x - p_v.x, y - p_v.y);
|
||||
}
|
||||
void Vector2i::operator-=(const Vector2i &p_v) {
|
||||
x -= p_v.x;
|
||||
y -= p_v.y;
|
||||
}
|
||||
|
||||
Vector2i Vector2i::operator*(const Vector2i &p_v1) const {
|
||||
return Vector2i(x * p_v1.x, y * p_v1.y);
|
||||
};
|
||||
|
||||
Vector2i Vector2i::operator*(const int &rvalue) const {
|
||||
return Vector2i(x * rvalue, y * rvalue);
|
||||
};
|
||||
void Vector2i::operator*=(const int &rvalue) {
|
||||
x *= rvalue;
|
||||
y *= rvalue;
|
||||
};
|
||||
|
||||
Vector2i Vector2i::operator/(const Vector2i &p_v1) const {
|
||||
return Vector2i(x / p_v1.x, y / p_v1.y);
|
||||
};
|
||||
|
||||
Vector2i Vector2i::operator/(const int &rvalue) const {
|
||||
return Vector2i(x / rvalue, y / rvalue);
|
||||
};
|
||||
|
||||
void Vector2i::operator/=(const int &rvalue) {
|
||||
x /= rvalue;
|
||||
y /= rvalue;
|
||||
};
|
||||
|
||||
Vector2i Vector2i::operator-() const {
|
||||
return Vector2i(-x, -y);
|
||||
}
|
||||
|
||||
bool Vector2i::operator==(const Vector2i &p_vec2) const {
|
||||
return x == p_vec2.x && y == p_vec2.y;
|
||||
}
|
||||
bool Vector2i::operator!=(const Vector2i &p_vec2) const {
|
||||
return x != p_vec2.x || y != p_vec2.y;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#ifndef VECTOR2_H
|
||||
#define VECTOR2_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* vector2.h */
|
||||
/*************************************************************************/
|
||||
@ -33,8 +34,6 @@
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/ustring.h"
|
||||
|
||||
struct Vector2i;
|
||||
|
||||
struct _NO_DISCARD_CLASS_ Vector2 {
|
||||
static const int AXIS_COUNT = 2;
|
||||
|
||||
@ -268,80 +267,4 @@ Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real
|
||||
typedef Vector2 Size2;
|
||||
typedef Vector2 Point2;
|
||||
|
||||
/* INTEGER STUFF */
|
||||
|
||||
struct _NO_DISCARD_CLASS_ Vector2i {
|
||||
enum Axis {
|
||||
AXIS_X,
|
||||
AXIS_Y,
|
||||
};
|
||||
|
||||
union {
|
||||
struct {
|
||||
union {
|
||||
int x;
|
||||
int width;
|
||||
};
|
||||
union {
|
||||
int y;
|
||||
int height;
|
||||
};
|
||||
};
|
||||
|
||||
int coord[2];
|
||||
};
|
||||
|
||||
_FORCE_INLINE_ int &operator[](int p_idx) {
|
||||
DEV_ASSERT((unsigned int)p_idx < 2);
|
||||
return coord[p_idx];
|
||||
}
|
||||
_FORCE_INLINE_ const int &operator[](int p_idx) const {
|
||||
DEV_ASSERT((unsigned int)p_idx < 2);
|
||||
return coord[p_idx];
|
||||
}
|
||||
|
||||
Vector2i operator+(const Vector2i &p_v) const;
|
||||
void operator+=(const Vector2i &p_v);
|
||||
Vector2i operator-(const Vector2i &p_v) const;
|
||||
void operator-=(const Vector2i &p_v);
|
||||
Vector2i operator*(const Vector2i &p_v1) const;
|
||||
|
||||
Vector2i operator*(const int &rvalue) const;
|
||||
void operator*=(const int &rvalue);
|
||||
|
||||
Vector2i operator/(const Vector2i &p_v1) const;
|
||||
|
||||
Vector2i operator/(const int &rvalue) const;
|
||||
|
||||
void operator/=(const int &rvalue);
|
||||
|
||||
Vector2i operator-() const;
|
||||
bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); }
|
||||
bool operator>(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y > p_vec2.y) : (x > p_vec2.x); }
|
||||
|
||||
bool operator==(const Vector2i &p_vec2) const;
|
||||
bool operator!=(const Vector2i &p_vec2) const;
|
||||
|
||||
real_t get_aspect() const { return width / (real_t)height; }
|
||||
|
||||
operator String() const { return String::num(x) + ", " + String::num(y); }
|
||||
|
||||
operator Vector2() const { return Vector2(x, y); }
|
||||
inline Vector2i(const Vector2 &p_vec2) {
|
||||
x = (int)p_vec2.x;
|
||||
y = (int)p_vec2.y;
|
||||
}
|
||||
inline Vector2i(int p_x, int p_y) {
|
||||
x = p_x;
|
||||
y = p_y;
|
||||
}
|
||||
inline Vector2i() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vector2i Size2i;
|
||||
typedef Vector2i Point2i;
|
||||
|
||||
#endif // VECTOR2_H
|
||||
|
82
core/math/vector2i.cpp
Normal file
82
core/math/vector2i.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*************************************************************************/
|
||||
/* vector2.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "vector2i.h"
|
||||
|
||||
Vector2i Vector2i::operator+(const Vector2i &p_v) const {
|
||||
return Vector2i(x + p_v.x, y + p_v.y);
|
||||
}
|
||||
void Vector2i::operator+=(const Vector2i &p_v) {
|
||||
x += p_v.x;
|
||||
y += p_v.y;
|
||||
}
|
||||
Vector2i Vector2i::operator-(const Vector2i &p_v) const {
|
||||
return Vector2i(x - p_v.x, y - p_v.y);
|
||||
}
|
||||
void Vector2i::operator-=(const Vector2i &p_v) {
|
||||
x -= p_v.x;
|
||||
y -= p_v.y;
|
||||
}
|
||||
|
||||
Vector2i Vector2i::operator*(const Vector2i &p_v1) const {
|
||||
return Vector2i(x * p_v1.x, y * p_v1.y);
|
||||
};
|
||||
|
||||
Vector2i Vector2i::operator*(const int &rvalue) const {
|
||||
return Vector2i(x * rvalue, y * rvalue);
|
||||
};
|
||||
void Vector2i::operator*=(const int &rvalue) {
|
||||
x *= rvalue;
|
||||
y *= rvalue;
|
||||
};
|
||||
|
||||
Vector2i Vector2i::operator/(const Vector2i &p_v1) const {
|
||||
return Vector2i(x / p_v1.x, y / p_v1.y);
|
||||
};
|
||||
|
||||
Vector2i Vector2i::operator/(const int &rvalue) const {
|
||||
return Vector2i(x / rvalue, y / rvalue);
|
||||
};
|
||||
|
||||
void Vector2i::operator/=(const int &rvalue) {
|
||||
x /= rvalue;
|
||||
y /= rvalue;
|
||||
};
|
||||
|
||||
Vector2i Vector2i::operator-() const {
|
||||
return Vector2i(-x, -y);
|
||||
}
|
||||
|
||||
bool Vector2i::operator==(const Vector2i &p_vec2) const {
|
||||
return x == p_vec2.x && y == p_vec2.y;
|
||||
}
|
||||
bool Vector2i::operator!=(const Vector2i &p_vec2) const {
|
||||
return x != p_vec2.x || y != p_vec2.y;
|
||||
}
|
115
core/math/vector2i.h
Normal file
115
core/math/vector2i.h
Normal file
@ -0,0 +1,115 @@
|
||||
#ifndef VECTOR2I_H
|
||||
#define VECTOR2I_H
|
||||
|
||||
/*************************************************************************/
|
||||
/* vector2.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/ustring.h"
|
||||
|
||||
#include "vector2.h"
|
||||
|
||||
struct _NO_DISCARD_CLASS_ Vector2i {
|
||||
enum Axis {
|
||||
AXIS_X,
|
||||
AXIS_Y,
|
||||
};
|
||||
|
||||
union {
|
||||
struct {
|
||||
union {
|
||||
int x;
|
||||
int width;
|
||||
};
|
||||
union {
|
||||
int y;
|
||||
int height;
|
||||
};
|
||||
};
|
||||
|
||||
int coord[2];
|
||||
};
|
||||
|
||||
_FORCE_INLINE_ int &operator[](int p_idx) {
|
||||
DEV_ASSERT((unsigned int)p_idx < 2);
|
||||
return coord[p_idx];
|
||||
}
|
||||
_FORCE_INLINE_ const int &operator[](int p_idx) const {
|
||||
DEV_ASSERT((unsigned int)p_idx < 2);
|
||||
return coord[p_idx];
|
||||
}
|
||||
|
||||
Vector2i operator+(const Vector2i &p_v) const;
|
||||
void operator+=(const Vector2i &p_v);
|
||||
Vector2i operator-(const Vector2i &p_v) const;
|
||||
void operator-=(const Vector2i &p_v);
|
||||
Vector2i operator*(const Vector2i &p_v1) const;
|
||||
|
||||
Vector2i operator*(const int &rvalue) const;
|
||||
void operator*=(const int &rvalue);
|
||||
|
||||
Vector2i operator/(const Vector2i &p_v1) const;
|
||||
|
||||
Vector2i operator/(const int &rvalue) const;
|
||||
|
||||
void operator/=(const int &rvalue);
|
||||
|
||||
Vector2i operator-() const;
|
||||
bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); }
|
||||
bool operator>(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y > p_vec2.y) : (x > p_vec2.x); }
|
||||
|
||||
bool operator==(const Vector2i &p_vec2) const;
|
||||
bool operator!=(const Vector2i &p_vec2) const;
|
||||
|
||||
real_t get_aspect() const { return width / (real_t)height; }
|
||||
|
||||
Vector2 to_vector2() const { return Vector2(x, y); }
|
||||
|
||||
operator String() const { return String::num(x) + ", " + String::num(y); }
|
||||
operator Vector2() const { return Vector2(x, y); }
|
||||
|
||||
inline Vector2i(const Vector2 &p_vec2) {
|
||||
x = (int)p_vec2.x;
|
||||
y = (int)p_vec2.y;
|
||||
}
|
||||
inline Vector2i(int p_x, int p_y) {
|
||||
x = p_x;
|
||||
y = p_y;
|
||||
}
|
||||
inline Vector2i() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vector2i Size2i;
|
||||
typedef Vector2i Point2i;
|
||||
|
||||
#endif // VECTOR2_H
|
@ -33,6 +33,7 @@
|
||||
#include "core/object.h"
|
||||
#include "core/os/main_loop.h"
|
||||
#include "core/os/thread_safe.h"
|
||||
#include "core/math/vector2i.h"
|
||||
|
||||
class Input : public Object {
|
||||
GDCLASS(Input, Object);
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "scene/resources/texture.h"
|
||||
#include "servers/visual/visual_server_raster.h"
|
||||
#include "servers/visual/visual_server_wrap_mt.h"
|
||||
#include "core/math/vector2i.h"
|
||||
|
||||
#ifdef HAVE_MNTENT
|
||||
#include <mntent.h>
|
||||
|
Loading…
Reference in New Issue
Block a user