summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorAnilforextra <anilforextra@gmail.com>2021-09-21 00:33:52 +0545
committerAnilforextra <anilforextra@gmail.com>2021-09-21 21:14:17 +0545
commit90908cd67d3f44ba70cc4b7b32f024ce508cc0ee (patch)
tree4c3f64aa550e6dc763b9776dded65560b67db2cc /core/math
parent87de2e7c4a38b1258d9a554c7f50cdbd8ac825fa (diff)
Add Get Center Method for Rect2/Rect2i and AABB.
Diffstat (limited to 'core/math')
-rw-r--r--core/math/aabb.h4
-rw-r--r--core/math/delaunay_2d.h2
-rw-r--r--core/math/rect2.h6
-rw-r--r--core/math/triangle_mesh.cpp4
4 files changed, 12 insertions, 4 deletions
diff --git a/core/math/aabb.h b/core/math/aabb.h
index e16246902a..97d92fbe37 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -118,6 +118,10 @@ public:
return position + size;
}
+ _FORCE_INLINE_ Vector3 get_center() const {
+ return position + (size * 0.5);
+ }
+
operator String() const;
_FORCE_INLINE_ AABB() {}
diff --git a/core/math/delaunay_2d.h b/core/math/delaunay_2d.h
index 95064e5700..2f80cb5634 100644
--- a/core/math/delaunay_2d.h
+++ b/core/math/delaunay_2d.h
@@ -101,7 +101,7 @@ public:
}
float delta_max = MAX(rect.size.width, rect.size.height);
- Vector2 center = rect.position + rect.size * 0.5;
+ Vector2 center = rect.get_center();
points.push_back(Vector2(center.x - 20 * delta_max, center.y - delta_max));
points.push_back(Vector2(center.x, center.y + 20 * delta_max));
diff --git a/core/math/rect2.h b/core/math/rect2.h
index ab0b489b4a..2557959fa2 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -46,6 +46,8 @@ struct Rect2 {
real_t get_area() const { return size.width * size.height; }
+ _FORCE_INLINE_ Vector2 get_center() const { return position + (size * 0.5); }
+
inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const {
if (p_include_borders) {
if (position.x > (p_rect.position.x + p_rect.size.width)) {
@@ -259,7 +261,7 @@ struct Rect2 {
}
_FORCE_INLINE_ bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const {
- Vector2 center = position + size * 0.5;
+ Vector2 center = get_center();
int side_plus = 0;
int side_minus = 0;
Vector2 end = position + size;
@@ -344,6 +346,8 @@ struct Rect2i {
int get_area() const { return size.width * size.height; }
+ _FORCE_INLINE_ Vector2i get_center() const { return position + (size / 2); }
+
inline bool intersects(const Rect2i &p_rect) const {
if (position.x > (p_rect.position.x + p_rect.size.width)) {
return false;
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index bf06c848c5..16d9652ef2 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -76,7 +76,7 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in
int index = r_max_alloc++;
BVH *_new = &p_bvh[index];
_new->aabb = aabb;
- _new->center = aabb.position + aabb.size * 0.5;
+ _new->center = aabb.get_center();
_new->face_index = -1;
_new->left = left;
_new->right = right;
@@ -152,7 +152,7 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) {
bw[i].left = -1;
bw[i].right = -1;
bw[i].face_index = i;
- bw[i].center = bw[i].aabb.position + bw[i].aabb.size * 0.5;
+ bw[i].center = bw[i].aabb.get_center();
}
vertices.resize(db.size());