summaryrefslogtreecommitdiffstats
path: root/src/core/AABB.cpp
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2021-02-28 16:52:06 -0300
committerGeorge Marques <george@gmarqu.es>2021-02-28 16:57:34 -0300
commitcba90d630177ce6c57b5537e74ef3eab4e9c1ea2 (patch)
tree439897c2673d4f0af2635abffe73699d0cae6a01 /src/core/AABB.cpp
parent77d41fa179e40560f1e264ed483638bf51713779 (diff)
downloadredot-cpp-cba90d630177ce6c57b5537e74ef3eab4e9c1ea2.tar.gz
Update clang-format to version 11
This is taken from the Godot repository, so formatting is similar. This updates the style rules as well. Also fix style in files to conform with this version.
Diffstat (limited to 'src/core/AABB.cpp')
-rw-r--r--src/core/AABB.cpp70
1 files changed, 16 insertions, 54 deletions
diff --git a/src/core/AABB.cpp b/src/core/AABB.cpp
index a67d459..2016cc7 100644
--- a/src/core/AABB.cpp
+++ b/src/core/AABB.cpp
@@ -7,7 +7,6 @@
namespace godot {
bool AABB::intersects(const AABB &p_aabb) const {
-
if (position.x >= (p_aabb.position.x + p_aabb.size.x))
return false;
if ((position.x + size.x) <= p_aabb.position.x)
@@ -25,7 +24,6 @@ bool AABB::intersects(const AABB &p_aabb) const {
}
bool AABB::intersects_inclusive(const AABB &p_aabb) const {
-
if (position.x > (p_aabb.position.x + p_aabb.size.x))
return false;
if ((position.x + size.x) < p_aabb.position.x)
@@ -43,7 +41,6 @@ bool AABB::intersects_inclusive(const AABB &p_aabb) const {
}
bool AABB::encloses(const AABB &p_aabb) const {
-
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@@ -59,7 +56,6 @@ bool AABB::encloses(const AABB &p_aabb) const {
}
Vector3 AABB::get_support(const Vector3 &p_normal) const {
-
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@@ -71,23 +67,29 @@ Vector3 AABB::get_support(const Vector3 &p_normal) const {
}
Vector3 AABB::get_endpoint(int p_point) const {
-
switch (p_point) {
- case 0: return Vector3(position.x, position.y, position.z);
- case 1: return Vector3(position.x, position.y, position.z + size.z);
- case 2: return Vector3(position.x, position.y + size.y, position.z);
- case 3: return Vector3(position.x, position.y + size.y, position.z + size.z);
- case 4: return Vector3(position.x + size.x, position.y, position.z);
- case 5: return Vector3(position.x + size.x, position.y, position.z + size.z);
- case 6: return Vector3(position.x + size.x, position.y + size.y, position.z);
- case 7: return Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
+ case 0:
+ return Vector3(position.x, position.y, position.z);
+ case 1:
+ return Vector3(position.x, position.y, position.z + size.z);
+ case 2:
+ return Vector3(position.x, position.y + size.y, position.z);
+ case 3:
+ return Vector3(position.x, position.y + size.y, position.z + size.z);
+ case 4:
+ return Vector3(position.x + size.x, position.y, position.z);
+ case 5:
+ return Vector3(position.x + size.x, position.y, position.z + size.z);
+ case 6:
+ return Vector3(position.x + size.x, position.y + size.y, position.z);
+ case 7:
+ return Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
};
ERR_FAIL_V(Vector3());
}
bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const {
-
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@@ -106,7 +108,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con
}
bool AABB::has_point(const Vector3 &p_point) const {
-
if (p_point.x < position.x)
return false;
if (p_point.y < position.y)
@@ -124,7 +125,6 @@ bool AABB::has_point(const Vector3 &p_point) const {
}
void AABB::expand_to(const Vector3 &p_vector) {
-
Vector3 begin = position;
Vector3 end = position + size;
@@ -147,7 +147,6 @@ void AABB::expand_to(const Vector3 &p_vector) {
}
void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const {
-
Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5);
Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z);
@@ -158,7 +157,6 @@ void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r
}
real_t AABB::get_longest_axis_size() const {
-
real_t max_size = size.x;
if (size.y > max_size) {
@@ -173,7 +171,6 @@ real_t AABB::get_longest_axis_size() const {
}
real_t AABB::get_shortest_axis_size() const {
-
real_t max_size = size.x;
if (size.y < max_size) {
@@ -188,7 +185,6 @@ real_t AABB::get_shortest_axis_size() const {
}
bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t0, real_t t1) const {
-
real_t divx = 1.0 / dir.x;
real_t divy = 1.0 / dir.y;
real_t divz = 1.0 / dir.z;
@@ -232,7 +228,6 @@ bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t
}
void AABB::grow_by(real_t p_amount) {
-
position.x -= p_amount;
position.y -= p_amount;
position.z -= p_amount;
@@ -242,21 +237,17 @@ void AABB::grow_by(real_t p_amount) {
}
real_t AABB::get_area() const {
-
return size.x * size.y * size.z;
}
bool AABB::operator==(const AABB &p_rval) const {
-
return ((position == p_rval.position) && (size == p_rval.size));
}
bool AABB::operator!=(const AABB &p_rval) const {
-
return ((position != p_rval.position) || (size != p_rval.size));
}
void AABB::merge_with(const AABB &p_aabb) {
-
Vector3 beg_1, beg_2;
Vector3 end_1, end_2;
Vector3 min, max;
@@ -279,7 +270,6 @@ void AABB::merge_with(const AABB &p_aabb) {
}
AABB AABB::intersection(const AABB &p_aabb) const {
-
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@@ -290,7 +280,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.x > dst_max.x || src_max.x < dst_min.x)
return AABB();
else {
-
min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x;
max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x;
}
@@ -298,7 +287,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.y > dst_max.y || src_max.y < dst_min.y)
return AABB();
else {
-
min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y;
max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y;
}
@@ -306,7 +294,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.z > dst_max.z || src_max.z < dst_min.z)
return AABB();
else {
-
min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z;
max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z;
}
@@ -315,7 +302,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
}
bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const {
-
Vector3 c1, c2;
Vector3 end = position + size;
real_t near = -1e20;
@@ -358,7 +344,6 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
}
bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip, Vector3 *r_normal) const {
-
real_t min = 0, max = 1;
int axis = 0;
real_t sign = 0;
@@ -372,7 +357,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
real_t csign;
if (seg_from < seg_to) {
-
if (seg_from > box_end || seg_to < box_begin)
return false;
real_t length = seg_to - seg_from;
@@ -381,7 +365,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
csign = -1.0;
} else {
-
if (seg_to > box_end || seg_from < box_begin)
return false;
real_t length = seg_to - seg_from;
@@ -416,7 +399,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
}
bool AABB::intersects_plane(const Plane &p_plane) const {
-
Vector3 points[8] = {
Vector3(position.x, position.y, position.z),
Vector3(position.x, position.y, position.z + size.z),
@@ -432,7 +414,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
bool under = false;
for (int i = 0; i < 8; i++) {
-
if (p_plane.distance_to(points[i]) > 0)
over = true;
else
@@ -443,7 +424,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
}
Vector3 AABB::get_longest_axis() const {
-
Vector3 axis(1, 0, 0);
real_t max_size = size.x;
@@ -460,7 +440,6 @@ Vector3 AABB::get_longest_axis() const {
return axis;
}
int AABB::get_longest_axis_index() const {
-
int axis = 0;
real_t max_size = size.x;
@@ -478,7 +457,6 @@ int AABB::get_longest_axis_index() const {
}
Vector3 AABB::get_shortest_axis() const {
-
Vector3 axis(1, 0, 0);
real_t max_size = size.x;
@@ -495,7 +473,6 @@ Vector3 AABB::get_shortest_axis() const {
return axis;
}
int AABB::get_shortest_axis_index() const {
-
int axis = 0;
real_t max_size = size.x;
@@ -513,7 +490,6 @@ int AABB::get_shortest_axis_index() const {
}
AABB AABB::merge(const AABB &p_with) const {
-
AABB aabb = *this;
aabb.merge_with(p_with);
return aabb;
@@ -524,24 +500,19 @@ AABB AABB::expand(const Vector3 &p_vector) const {
return aabb;
}
AABB AABB::grow(real_t p_by) const {
-
AABB aabb = *this;
aabb.grow_by(p_by);
return aabb;
}
void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
-
ERR_FAIL_INDEX(p_edge, 12);
switch (p_edge) {
-
case 0: {
-
r_from = Vector3(position.x + size.x, position.y, position.z);
r_to = Vector3(position.x, position.y, position.z);
} break;
case 1: {
-
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
r_to = Vector3(position.x + size.x, position.y, position.z);
} break;
@@ -551,18 +522,15 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
} break;
case 3: {
-
r_from = Vector3(position.x, position.y, position.z);
r_to = Vector3(position.x, position.y, position.z + size.z);
} break;
case 4: {
-
r_from = Vector3(position.x, position.y + size.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 5: {
-
r_from = Vector3(position.x + size.x, position.y + size.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
} break;
@@ -572,31 +540,26 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
} break;
case 7: {
-
r_from = Vector3(position.x, position.y + size.y, position.z + size.z);
r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 8: {
-
r_from = Vector3(position.x, position.y, position.z + size.z);
r_to = Vector3(position.x, position.y + size.y, position.z + size.z);
} break;
case 9: {
-
r_from = Vector3(position.x, position.y, position.z);
r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 10: {
-
r_from = Vector3(position.x + size.x, position.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 11: {
-
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
@@ -605,7 +568,6 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
}
AABB::operator String() const {
-
return String() + position + " - " + size;
}