added grow functions to Rect2

- grow_individual
 - grow_margin

(cherry picked from commit 66b308925c)
This commit is contained in:
toger5 2017-05-29 04:36:14 -07:00 committed by Rémi Verschelde
parent 314fa89978
commit e1f4abe062
2 changed files with 23 additions and 0 deletions

View File

@ -327,6 +327,25 @@ struct Rect2 {
g.size.height += p_by * 2; g.size.height += p_by * 2;
return g; return g;
} }
inline Rect2 grow_margin(Margin p_margin, real_t p_amount) const {
Rect2 g = *this;
g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0,
(MARGIN_TOP == p_margin) ? p_amount : 0,
(MARGIN_RIGHT == p_margin) ? p_amount : 0,
(MARGIN_BOTTOM == p_margin) ? p_amount : 0);
return g;
}
inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const {
Rect2 g = *this;
g.pos.x -= p_left;
g.pos.y -= p_top;
g.size.width += p_left + p_right;
g.size.height += p_top + p_bottom;
return g;
}
inline Rect2 expand(const Vector2 &p_vector) const { inline Rect2 expand(const Vector2 &p_vector) const {

View File

@ -345,6 +345,8 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Rect2, merge); VCALL_LOCALMEM1R(Rect2, merge);
VCALL_LOCALMEM1R(Rect2, has_point); VCALL_LOCALMEM1R(Rect2, has_point);
VCALL_LOCALMEM1R(Rect2, grow); VCALL_LOCALMEM1R(Rect2, grow);
VCALL_LOCALMEM2R(Rect2, grow_margin);
VCALL_LOCALMEM4R(Rect2, grow_individual);
VCALL_LOCALMEM1R(Rect2, expand); VCALL_LOCALMEM1R(Rect2, expand);
VCALL_LOCALMEM0R(Vector3, min_axis); VCALL_LOCALMEM0R(Vector3, min_axis);
@ -1397,6 +1399,8 @@ void register_variant_methods() {
ADDFUNC1(RECT2, RECT2, Rect2, merge, RECT2, "b", varray()); ADDFUNC1(RECT2, RECT2, Rect2, merge, RECT2, "b", varray());
ADDFUNC1(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray()); ADDFUNC1(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray());
ADDFUNC1(RECT2, RECT2, Rect2, grow, REAL, "by", varray()); ADDFUNC1(RECT2, RECT2, Rect2, grow, REAL, "by", varray());
ADDFUNC2(RECT2, RECT2, Rect2, grow_margin, INT, "margin", REAL, "by", varray());
ADDFUNC4(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", varray());
ADDFUNC1(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray()); ADDFUNC1(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray());
ADDFUNC0(VECTOR3, INT, Vector3, min_axis, varray()); ADDFUNC0(VECTOR3, INT, Vector3, min_axis, varray());