@ -65,35 +65,35 @@ enum VAlign {
struct Vector2 {
union {
floa t x ;
floa t width ;
real_ t x ;
real_ t width ;
} ;
union {
floa t y ;
floa t height ;
real_ t y ;
real_ t height ;
} ;
_FORCE_INLINE_ floa t& operator [ ] ( int p_idx ) {
_FORCE_INLINE_ real_ t& operator [ ] ( int p_idx ) {
return p_idx ? y : x ;
}
_FORCE_INLINE_ const floa t& operator [ ] ( int p_idx ) const {
_FORCE_INLINE_ const real_ t& operator [ ] ( int p_idx ) const {
return p_idx ? y : x ;
}
void normalize ( ) ;
Vector2 normalized ( ) const ;
floa t length ( ) const ;
floa t length_squared ( ) const ;
real_ t length ( ) const ;
real_ t length_squared ( ) const ;
floa t distance_to ( const Vector2 & p_vector2 ) const ;
floa t distance_squared_to ( const Vector2 & p_vector2 ) const ;
floa t angle_to ( const Vector2 & p_vector2 ) const ;
floa t angle_to_point ( const Vector2 & p_vector2 ) const ;
real_ t distance_to ( const Vector2 & p_vector2 ) const ;
real_ t distance_squared_to ( const Vector2 & p_vector2 ) const ;
real_ t angle_to ( const Vector2 & p_vector2 ) const ;
real_ t angle_to_point ( const Vector2 & p_vector2 ) const ;
floa t dot ( const Vector2 & p_other ) const ;
floa t cross ( const Vector2 & p_other ) const ;
real_ t dot ( const Vector2 & p_other ) const ;
real_ t cross ( const Vector2 & p_other ) const ;
Vector2 cross ( real_t p_other ) const ;
Vector2 project ( const Vector2 & p_vec ) const ;
@ -101,10 +101,10 @@ struct Vector2 {
Vector2 clamped ( real_t p_len ) const ;
_FORCE_INLINE_ static Vector2 linear_interpolate ( const Vector2 & p_a , const Vector2 & p_b , floa t p_t ) ;
_FORCE_INLINE_ Vector2 linear_interpolate ( const Vector2 & p_b , floa t p_t ) const ;
Vector2 cubic_interpolate ( const Vector2 & p_b , const Vector2 & p_pre_a , const Vector2 & p_post_b , floa t p_t ) const ;
Vector2 cubic_interpolate_soft ( const Vector2 & p_b , const Vector2 & p_pre_a , const Vector2 & p_post_b , floa t p_t ) const ;
_FORCE_INLINE_ static Vector2 linear_interpolate ( const Vector2 & p_a , const Vector2 & p_b , real_ t p_t ) ;
_FORCE_INLINE_ Vector2 linear_interpolate ( const Vector2 & p_b , real_ t p_t ) const ;
Vector2 cubic_interpolate ( const Vector2 & p_b , const Vector2 & p_pre_a , const Vector2 & p_post_b , real_ t p_t ) const ;
Vector2 cubic_interpolate_soft ( const Vector2 & p_b , const Vector2 & p_pre_a , const Vector2 & p_post_b , real_ t p_t ) const ;
Vector2 slide ( const Vector2 & p_vec ) const ;
Vector2 reflect ( const Vector2 & p_vec ) const ;
@ -115,15 +115,15 @@ struct Vector2 {
void operator - = ( const Vector2 & p_v ) ;
Vector2 operator * ( const Vector2 & p_v1 ) const ;
Vector2 operator * ( const floa t & rvalue ) const ;
void operator * = ( const floa t & rvalue ) ;
Vector2 operator * ( const real_ t & rvalue ) const ;
void operator * = ( const real_ t & rvalue ) ;
void operator * = ( const Vector2 & rvalue ) { * this = * this * rvalue ; }
Vector2 operator / ( const Vector2 & p_v1 ) const ;
Vector2 operator / ( const floa t & rvalue ) const ;
Vector2 operator / ( const real_ t & rvalue ) const ;
void operator / = ( const floa t & rvalue ) ;
void operator / = ( const real_ t & rvalue ) ;
Vector2 operator - ( ) const ;
@ -135,10 +135,10 @@ struct Vector2 {
real_t angle ( ) const ;
void set_rotation ( floa t p_radians ) {
void set_rotation ( real_ t p_radians ) {
x = Math : : sin ( p_radians ) ;
y = Math : : co s( p_radians ) ;
x = Math : : co s( p_radians ) ;
y = Math : : sin ( p_radians ) ;
}
_FORCE_INLINE_ Vector2 abs ( ) const {
@ -146,7 +146,7 @@ struct Vector2 {
return Vector2 ( Math : : abs ( x ) , Math : : abs ( y ) ) ;
}
Vector2 rotated ( floa t p_by ) const ;
Vector2 rotated ( real_ t p_by ) const ;
Vector2 tangent ( ) const {
return Vector2 ( y , - x ) ;
@ -154,12 +154,12 @@ struct Vector2 {
Vector2 floor ( ) const ;
Vector2 snapped ( const Vector2 & p_by ) const ;
floa t get_aspect ( ) const { return width / height ; }
real_ t get_aspect ( ) const { return width / height ; }
operator String ( ) const { return String : : num ( x ) + " , " + String : : num ( y ) ; }
_FORCE_INLINE_ Vector2 ( float p_x , floa t p_y ) { x = p_x ; y = p_y ; }
_FORCE_INLINE_ Vector2 ( real_t p_x , real_ t p_y ) { x = p_x ; y = p_y ; }
_FORCE_INLINE_ Vector2 ( ) { x = 0 ; y = 0 ; }
} ;
@ -169,12 +169,12 @@ _FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2& p_vec)
}
_FORCE_INLINE_ Vector2 operator * ( floa t p_scalar , const Vector2 & p_vec ) {
_FORCE_INLINE_ Vector2 operator * ( real_ t p_scalar , const Vector2 & p_vec ) {
return p_vec * p_scalar ;
}
Vector2 Vector2 : : linear_interpolate ( const Vector2 & p_b , floa t p_t ) const {
Vector2 Vector2 : : linear_interpolate ( const Vector2 & p_b , real_ t p_t ) const {
Vector2 res = * this ;
@ -185,7 +185,7 @@ Vector2 Vector2::linear_interpolate(const Vector2& p_b,float p_t) const {
}
Vector2 Vector2 : : linear_interpolate ( const Vector2 & p_a , const Vector2 & p_b , floa t p_t ) {
Vector2 Vector2 : : linear_interpolate ( const Vector2 & p_a , const Vector2 & p_b , real_ t p_t ) {
Vector2 res = p_a ;
@ -211,7 +211,7 @@ struct Rect2 {
const Vector2 & get_size ( ) const { return size ; }
void set_size ( const Vector2 & p_size ) { size = p_size ; }
floa t get_area ( ) const { return size . width * size . height ; }
real_ t get_area ( ) const { return size . width * size . height ; }
inline bool intersects ( const Rect2 & p_rect ) const {
if ( pos . x > = ( p_rect . pos . x + p_rect . size . width ) )
@ -226,9 +226,9 @@ struct Rect2 {
return true ;
}
inline floa t distance_to ( const Vector2 & p_point ) const {
inline real_ t distance_to ( const Vector2 & p_point ) const {
floa t dist = 1e20 ;
real_ t dist = 1e20 ;
if ( p_point . x < pos . x ) {
dist = MIN ( dist , pos . x - p_point . x ) ;
@ -359,7 +359,7 @@ struct Rect2 {
operator String ( ) const { return String ( pos ) + " , " + String ( size ) ; }
Rect2 ( ) { }
Rect2 ( float p_x , float p_y , float p_width , floa t p_height ) { pos = Point2 ( p_x , p_y ) ; size = Size2 ( p_width , p_height ) ; }
Rect2 ( real_t p_x , real_t p_y , real_t p_width , real_ t 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 ; }
} ;
@ -407,7 +407,7 @@ struct Point2i {
bool operator = = ( const Point2i & p_vec2 ) const ;
bool operator ! = ( const Point2i & p_vec2 ) const ;
floa t get_aspect ( ) const { return width / ( floa t) height ; }
real_ t get_aspect ( ) const { return width / ( real_ t) height ; }
operator String ( ) const { return String : : num ( x ) + " , " + String : : num ( y ) ; }
@ -552,11 +552,21 @@ struct Rect2i {
struct Matrix32 {
// Warning #1: basis of Matrix32 is stored differently from Matrix3. In terms of elements array, the basis matrix looks like "on paper":
// M = (elements[0][0] elements[1][0])
// (elements[0][1] elements[1][1])
// This is such that the columns, which can be interpreted as basis vectors of the coordinate system "painted" on the object, can be accessed as elements[i].
// Note that this is the opposite of the indices in mathematical texts, meaning: $M_{12}$ in a math book corresponds to elements[1][0] here.
// This requires additional care when working with explicit indices.
// See https://en.wikipedia.org/wiki/Row-_and_column-major_order for further reading.
// Warning #2: 2D be aware that unlike 3D code, 2D code uses a left-handed coordinate system: Y-axis points down,
// and angle is measure from +X to +Y in a clockwise-fashion.
Vector2 elements [ 3 ] ;
_FORCE_INLINE_ float tdotx ( const Vector2 & v ) const { return elements [ 0 ] [ 0 ] * v . x + elements [ 1 ] [ 0 ] * v . y ; }
_FORCE_INLINE_ float tdoty ( const Vector2 & v ) const { return elements [ 0 ] [ 1 ] * v . x + elements [ 1 ] [ 1 ] * v . y ; }
_FORCE_INLINE_ real_ t tdotx ( const Vector2 & v ) const { return elements [ 0 ] [ 0 ] * v . x + elements [ 1 ] [ 0 ] * v . y ; }
_FORCE_INLINE_ real_ t tdoty ( const Vector2 & v ) const { return elements [ 0 ] [ 1 ] * v . x + elements [ 1 ] [ 1 ] * v . y ; }
const Vector2 & operator [ ] ( int p_idx ) const { return elements [ p_idx ] ; }
Vector2 & operator [ ] ( int p_idx ) { return elements [ p_idx ] ; }
@ -580,7 +590,7 @@ struct Matrix32 {
void translate ( real_t p_tx , real_t p_ty ) ;
void translate ( const Vector2 & p_translation ) ;
floa t basis_determinant ( ) const ;
real_ t basis_determinant ( ) const ;
Size2 get_scale ( ) const ;
@ -590,7 +600,7 @@ struct Matrix32 {
Matrix32 scaled ( const Size2 & p_scale ) const ;
Matrix32 basis_scaled ( const Size2 & p_scale ) const ;
Matrix32 translated ( const Vector2 & p_offset ) const ;
Matrix32 rotated ( floa t p_phi ) const ;
Matrix32 rotated ( real_ t p_phi ) const ;
Matrix32 untranslated ( ) const ;
@ -603,7 +613,7 @@ struct Matrix32 {
void operator * = ( const Matrix32 & p_transform ) ;
Matrix32 operator * ( const Matrix32 & p_transform ) const ;
Matrix32 interpolate_with ( const Matrix32 & p_transform , floa t p_c ) const ;
Matrix32 interpolate_with ( const Matrix32 & p_transform , real_ t p_c ) const ;
_FORCE_INLINE_ Vector2 basis_xform ( const Vector2 & p_vec ) const ;
_FORCE_INLINE_ Vector2 basis_xform_inv ( const Vector2 & p_vec ) const ;
@ -834,8 +844,8 @@ void Matrix32::set_rotation_and_scale(real_t p_rot,const Size2& p_scale) {
elements [ 0 ] [ 0 ] = Math : : cos ( p_rot ) * p_scale . x ;
elements [ 1 ] [ 1 ] = Math : : cos ( p_rot ) * p_scale . y ;
elements [ 0] [ 1 ] = - Math : : sin ( p_rot ) * p_scale . x ;
elements [ 1] [ 0 ] = Math : : sin ( p_rot ) * p_scale . y ;
elements [ 1] [ 0 ] = - Math : : sin ( p_rot ) * p_scale . y ;
elements [ 0] [ 1 ] = Math : : sin ( p_rot ) * p_scale . x ;
}