Rect2: add function returning same rect with positive w and h

This commit is contained in:
Poommetee Ketson 2017-11-28 00:41:29 +07:00
parent d992eb1b25
commit 5c9be411eb
3 changed files with 7 additions and 29 deletions

View file

@ -222,35 +222,6 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
(2.0 * p0 - 5.0 * p1 + 4 * p2 - p3) * t2 +
(-p0 + 3.0 * p1 - 3.0 * p2 + p3) * t3);
return out;
/*
real_t mu = p_t;
real_t mu2 = mu*mu;
Vector2 a0 = p_post_b - p_b - p_pre_a + *this;
Vector2 a1 = p_pre_a - *this - a0;
Vector2 a2 = p_b - p_pre_a;
Vector2 a3 = *this;
return ( a0*mu*mu2 + a1*mu2 + a2*mu + a3 );
*/
/*
real_t t = p_t;
real_t t2 = t*t;
real_t t3 = t2*t;
real_t a = 2.0*t3- 3.0*t2 + 1;
real_t b = -2.0*t3+ 3.0*t2;
real_t c = t3- 2.0*t2 + t;
real_t d = t3- t2;
Vector2 p_a=*this;
return Vector2(
(a * p_a.x) + (b *p_b.x) + (c * p_pre_a.x) + (d * p_post_b.x),
(a * p_a.y) + (b *p_b.y) + (c * p_pre_a.y) + (d * p_post_b.y)
);
*/
}
// slide returns the component of the vector along the given plane, specified by its normal vector.

View file

@ -382,6 +382,11 @@ struct Rect2 {
size = end - begin;
}
inline Rect2 abs() const {
return Rect2(Point2(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs());
}
operator String() const { return String(position) + ", " + String(size); }
Rect2() {}

View file

@ -360,6 +360,7 @@ struct _VariantCall {
VCALL_LOCALMEM2R(Rect2, grow_margin);
VCALL_LOCALMEM4R(Rect2, grow_individual);
VCALL_LOCALMEM1R(Rect2, expand);
VCALL_LOCALMEM0R(Rect2, abs);
VCALL_LOCALMEM0R(Vector3, min_axis);
VCALL_LOCALMEM0R(Vector3, max_axis);
@ -1526,6 +1527,7 @@ void register_variant_methods() {
ADDFUNC2R(RECT2, RECT2, Rect2, grow_margin, INT, "margin", REAL, "by", varray());
ADDFUNC4R(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", varray());
ADDFUNC1R(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray());
ADDFUNC0R(RECT2, RECT2, Rect2, abs, varray());
ADDFUNC0R(VECTOR3, INT, Vector3, min_axis, varray());
ADDFUNC0R(VECTOR3, INT, Vector3, max_axis, varray());