diff options
| author | Rémi Verschelde | 2017-03-05 16:44:50 +0100 |
|---|---|---|
| committer | Rémi Verschelde | 2017-03-05 16:44:50 +0100 |
| commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
| tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /core/math/bsp_tree.h | |
| parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) | |
| download | godot-5dbf180.tar.gz godot-5dbf180.tar.zst godot-5dbf180.zip | |
A Whole New World (clang-format edition)
I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?
I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon
A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format
A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
Diffstat (limited to 'core/math/bsp_tree.h')
| -rw-r--r-- | core/math/bsp_tree.h | 105 |
1 files changed, 49 insertions, 56 deletions
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h index c0071438d..4cfac35a2 100644 --- a/core/math/bsp_tree.h +++ b/core/math/bsp_tree.h @@ -29,25 +29,24 @@ #ifndef BSP_TREE_H #define BSP_TREE_H +#include "dvector.h" +#include "face3.h" +#include "method_ptrcall.h" #include "plane.h" #include "rect3.h" -#include "face3.h" -#include "vector.h" -#include "dvector.h" #include "variant.h" -#include "method_ptrcall.h" +#include "vector.h" /** @author Juan Linietsky <reduzio@gmail.com> */ class BSP_Tree { public: - enum { - UNDER_LEAF=0xFFFF, - OVER_LEAF=0xFFFE, - MAX_NODES=0xFFFE, - MAX_PLANES=(1<<16) + UNDER_LEAF = 0xFFFF, + OVER_LEAF = 0xFFFE, + MAX_NODES = 0xFFFE, + MAX_PLANES = (1 << 16) }; struct Node { @@ -57,7 +56,6 @@ public: uint16_t over; }; - private: // thanks to the properties of Vector, // this class can be assigned and passed around between threads @@ -68,95 +66,90 @@ private: Rect3 aabb; real_t error_radius; - int _get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const; + int _get_points_inside(int p_node, const Vector3 *p_points, int *p_indices, const Vector3 &p_center, const Vector3 &p_half_extents, int p_indices_count) const; - template<class T> - bool _test_convex(const Node* p_nodes, const Plane* p_planes,int p_current, const T& p_convex) const; + template <class T> + bool _test_convex(const Node *p_nodes, const Plane *p_planes, int p_current, const T &p_convex) const; public: - - bool is_empty() const { return nodes.size()==0; } + bool is_empty() const { return nodes.size() == 0; } Vector<Node> get_nodes() const; Vector<Plane> get_planes() const; Rect3 get_aabb() const; - bool point_is_inside(const Vector3& p_point) const; - int get_points_inside(const Vector3* p_points, int p_point_count) const; - template<class T> - bool convex_is_inside(const T& p_convex) const; + bool point_is_inside(const Vector3 &p_point) const; + int get_points_inside(const Vector3 *p_points, int p_point_count) const; + template <class T> + bool convex_is_inside(const T &p_convex) const; operator Variant() const; - void from_aabb(const Rect3& p_aabb); + void from_aabb(const Rect3 &p_aabb); BSP_Tree(); - BSP_Tree(const Variant& p_variant); - BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius=0); - BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius=0); + BSP_Tree(const Variant &p_variant); + BSP_Tree(const PoolVector<Face3> &p_faces, real_t p_error_radius = 0); + BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3 &p_aabb, real_t p_error_radius = 0); ~BSP_Tree(); - }; -template<class T> -bool BSP_Tree::_test_convex(const Node* p_nodes, const Plane* p_planes,int p_current, const T& p_convex) const { +template <class T> +bool BSP_Tree::_test_convex(const Node *p_nodes, const Plane *p_planes, int p_current, const T &p_convex) const { - if (p_current==UNDER_LEAF) + if (p_current == UNDER_LEAF) return true; - else if (p_current==OVER_LEAF) + else if (p_current == OVER_LEAF) return false; - bool collided=false; - const Node&n=p_nodes[p_current]; + bool collided = false; + const Node &n = p_nodes[p_current]; - const Plane& p=p_planes[n.plane]; + const Plane &p = p_planes[n.plane]; - real_t min,max; - p_convex.project_range(p.normal,min,max); + real_t min, max; + p_convex.project_range(p.normal, min, max); bool go_under = min < p.d; bool go_over = max >= p.d; - if (go_under && _test_convex(p_nodes,p_planes,n.under,p_convex)) - collided=true; - if (go_over && _test_convex(p_nodes,p_planes,n.over,p_convex)) - collided=true; + if (go_under && _test_convex(p_nodes, p_planes, n.under, p_convex)) + collided = true; + if (go_over && _test_convex(p_nodes, p_planes, n.over, p_convex)) + collided = true; return collided; - } -template<class T> -bool BSP_Tree::convex_is_inside(const T& p_convex) const { +template <class T> +bool BSP_Tree::convex_is_inside(const T &p_convex) const { int node_count = nodes.size(); - if (node_count==0) + if (node_count == 0) return false; - const Node* nodes=&this->nodes[0]; - const Plane* planes = &this->planes[0]; + const Node *nodes = &this->nodes[0]; + const Plane *planes = &this->planes[0]; - return _test_convex(nodes,planes,node_count-1,p_convex); + return _test_convex(nodes, planes, node_count - 1, p_convex); } - #ifdef PTRCALL_ENABLED - -template<> +template <> struct PtrToArg<BSP_Tree> { - _FORCE_INLINE_ static BSP_Tree convert(const void* p_ptr) { - BSP_Tree s( Variant( *reinterpret_cast<const Dictionary*>(p_ptr) ) ); + _FORCE_INLINE_ static BSP_Tree convert(const void *p_ptr) { + BSP_Tree s(Variant(*reinterpret_cast<const Dictionary *>(p_ptr))); return s; } - _FORCE_INLINE_ static void encode(BSP_Tree p_val,void* p_ptr) { - Dictionary *d = reinterpret_cast<Dictionary*>(p_ptr); - *d=Variant(p_val); + _FORCE_INLINE_ static void encode(BSP_Tree p_val, void *p_ptr) { + Dictionary *d = reinterpret_cast<Dictionary *>(p_ptr); + *d = Variant(p_val); } }; -template<> -struct PtrToArg<const BSP_Tree&> { - _FORCE_INLINE_ static BSP_Tree convert(const void* p_ptr) { - BSP_Tree s( Variant( *reinterpret_cast<const Dictionary*>(p_ptr) ) ); +template <> +struct PtrToArg<const BSP_Tree &> { + _FORCE_INLINE_ static BSP_Tree convert(const void *p_ptr) { + BSP_Tree s(Variant(*reinterpret_cast<const Dictionary *>(p_ptr))); return s; } }; |
