diff options
Diffstat (limited to 'core/math/math_2d.h')
-rw-r--r-- | core/math/math_2d.h | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 1171364671..ad4655b8f7 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -35,15 +35,15 @@ @author Juan Linietsky <reduzio@gmail.com> */ enum Margin { - + MARGIN_LEFT, MARGIN_TOP, MARGIN_RIGHT, - MARGIN_BOTTOM + MARGIN_BOTTOM }; enum Orientation { - + HORIZONTAL, VERTICAL }; @@ -63,7 +63,7 @@ enum VAlign { }; struct Vector2 { - + union { float x; float width; @@ -87,7 +87,7 @@ struct Vector2 { float length() const; float length_squared() const; - float distance_to(const Vector2& p_vector2) const; + float distance_to(const Vector2& p_vector2) const; float distance_squared_to(const Vector2& p_vector2) const; float angle_to(const Vector2& p_vector2) const; float angle_to_point(const Vector2& p_vector2) const; @@ -114,19 +114,19 @@ struct Vector2 { Vector2 operator-(const Vector2& p_v) const; void operator-=(const Vector2& p_v); Vector2 operator*(const Vector2 &p_v1) const; - + Vector2 operator*(const float &rvalue) const; void operator*=(const float &rvalue); void operator*=(const Vector2 &rvalue) { *this = *this * rvalue; } Vector2 operator/(const Vector2 &p_v1) const; - + Vector2 operator/(const float &rvalue) const; - + void operator/=(const float &rvalue); - + Vector2 operator-() const; - + bool operator==(const Vector2& p_vec2) const; bool operator!=(const Vector2& p_vec2) const; @@ -151,14 +151,14 @@ struct Vector2 { return Vector2(y,-x); } - + Vector2 floor() const; Vector2 snapped(const Vector2& p_by) const; float get_aspect() const { return width/height; } - + operator String() const { return String::num(x)+","+String::num(y); } - + _FORCE_INLINE_ Vector2(float p_x,float p_y) { x=p_x; y=p_y; } _FORCE_INLINE_ Vector2() { x=0; y=0; } }; @@ -202,7 +202,7 @@ struct Matrix32; struct Rect2 { - + Point2 pos; Size2 size; @@ -213,7 +213,7 @@ struct Rect2 { float get_area() const { return size.width*size.height; } - inline bool intersects(const Rect2& p_rect) const { + inline bool intersects(const Rect2& p_rect) const { if ( pos.x >= (p_rect.pos.x + p_rect.size.width) ) return false; if ( (pos.x+size.width) <= p_rect.pos.x ) @@ -222,7 +222,7 @@ struct Rect2 { return false; if ( (pos.y+size.height) <= p_rect.pos.y ) return false; - + return true; } @@ -254,73 +254,73 @@ struct Rect2 { bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=NULL, Point2* r_normal=NULL) const; inline bool encloses(const Rect2& p_rect) const { - + return (p_rect.pos.x>=pos.x) && (p_rect.pos.y>=pos.y) && ((p_rect.pos.x+p_rect.size.x)<(pos.x+size.x)) && ((p_rect.pos.y+p_rect.size.y)<(pos.y+size.y)); - + } - + inline bool has_no_area() const { - + return (size.x<=0 || size.y<=0); - + } inline Rect2 clip(const Rect2& p_rect) const { /// return a clipped rect - + Rect2 new_rect=p_rect; - + if (!intersects( new_rect )) return Rect2(); - + new_rect.pos.x = MAX( p_rect.pos.x , pos.x ); new_rect.pos.y = MAX( p_rect.pos.y , pos.y ); - + Point2 p_rect_end=p_rect.pos+p_rect.size; Point2 end=pos+size; - + new_rect.size.x=MIN(p_rect_end.x,end.x) - new_rect.pos.x; new_rect.size.y=MIN(p_rect_end.y,end.y) - new_rect.pos.y; - + return new_rect; } - + inline Rect2 merge(const Rect2& p_rect) const { ///< return a merged rect - + Rect2 new_rect; - + new_rect.pos.x=MIN( p_rect.pos.x , pos.x ); new_rect.pos.y=MIN( p_rect.pos.y , pos.y ); - - + + new_rect.size.x = MAX( p_rect.pos.x+p_rect.size.x , pos.x+size.x ); new_rect.size.y = MAX( p_rect.pos.y+p_rect.size.y , pos.y+size.y ); - + new_rect.size = new_rect.size - new_rect.pos; //make relative again - + return new_rect; }; inline bool has_point(const Point2& p_point) const { if (p_point.x < pos.x) - return false; + return false; if (p_point.y < pos.y) - return false; - + return false; + if (p_point.x >= (pos.x+size.x) ) - return false; + return false; if (p_point.y >= (pos.y+size.y) ) - return false; - + return false; + return true; } - + inline bool no_area() const { return (size.width<=0 || size.height<=0 ); } - + bool operator==(const Rect2& p_rect) const { return pos==p_rect.pos && size==p_rect.size; } bool operator!=(const Rect2& p_rect) const { return pos!=p_rect.pos || size!=p_rect.size; } - + inline Rect2 grow(real_t p_by) const { - + Rect2 g=*this; g.pos.x-=p_by; g.pos.y-=p_by; @@ -357,9 +357,9 @@ struct Rect2 { operator String() const { return String(pos)+","+String(size); } - + Rect2() {} - Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); } + Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); } Rect2( const Point2& p_pos, const Size2& p_size ) { pos=p_pos; size=p_size; } }; |