Implemented the new methods for Rect2.

This commit is contained in:
Relintai 2023-05-27 22:06:04 +02:00
parent a77167cf9d
commit fb11fd8338
2 changed files with 145 additions and 50 deletions

View File

@ -30,6 +30,7 @@
#include "gdn/rect2.h"
#include "core/math/rect2.h"
#include "core/math/transform_2d.h"
#include "core/variant/variant.h"
@ -39,17 +40,86 @@ extern "C" {
static_assert(sizeof(pandemonium_rect2) == sizeof(Rect2), "Rect2 size mismatch");
pandemonium_vector2 GDAPI pandemonium_rect2_get_position(const pandemonium_rect2 *p_self) {
pandemonium_vector2 dest;
Vector2 *d = (Vector2 *)&dest;
const Rect2 *self = (const Rect2 *)p_self;
*d = self->get_position();
return dest;
}
void GDAPI pandemonium_rect2_set_position(pandemonium_rect2 *p_self, const pandemonium_vector2 *p_pos) {
Rect2 *self = (Rect2 *)p_self;
const Vector2 *position = (const Vector2 *)p_pos;
self->set_position(*position);
}
pandemonium_vector2 GDAPI pandemonium_rect2_get_size(const pandemonium_rect2 *p_self) {
pandemonium_vector2 dest;
Vector2 *d = (Vector2 *)&dest;
const Rect2 *self = (const Rect2 *)p_self;
*d = self->get_size();
return dest;
}
void GDAPI pandemonium_rect2_set_size(pandemonium_rect2 *p_self, const pandemonium_vector2 *p_size) {
Rect2 *self = (Rect2 *)p_self;
const Vector2 *size = (const Vector2 *)p_size;
self->set_size(*size);
}
pandemonium_real GDAPI pandemonium_rect2_get_area(const pandemonium_rect2 *p_self) {
const Rect2 *self = (const Rect2 *)p_self;
return self->get_area();
}
pandemonium_vector2 GDAPI pandemonium_rect2_get_center(const pandemonium_rect2 *p_self) {
pandemonium_vector2 dest;
Vector2 *d = (Vector2 *)&dest;
const Rect2 *self = (const Rect2 *)p_self;
*d = self->get_center();
return dest;
}
pandemonium_bool GDAPI pandemonium_rect2_intersects(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b) {
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *b = (const Rect2 *)p_b;
return self->intersects(*b);
}
pandemonium_real GDAPI pandemonium_rect2_distance_to(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_point) {
const Rect2 *self = (const Rect2 *)p_self;
const Vector2 *point = (const Vector2 *)p_point;
return self->distance_to(*point);
}
pandemonium_bool GDAPI pandemonium_rect2_intersects_transformed(const pandemonium_rect2 *p_self, const pandemonium_transform2d *p_xform, const pandemonium_rect2 *p_rect) {
const Rect2 *self = (const Rect2 *)p_self;
const Transform2D *xform = (const Transform2D *)p_xform;
const Rect2 *rect = (const Rect2 *)p_rect;
return self->intersects_transformed(*xform, *rect);
}
pandemonium_bool GDAPI pandemonium_rect2_intersects_segment(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_from, const pandemonium_vector2 *p_to) {
const Rect2 *self = (const Rect2 *)p_self;
const Vector2 *from = (const Vector2 *)p_from;
const Vector2 *to = (const Vector2 *)p_to;
return self->intersects_segment(*from, *to);
}
pandemonium_bool GDAPI pandemonium_rect2_intersects_segment_pos(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_from, const pandemonium_vector2 *p_to, pandemonium_vector2 *r_pos) {
const Rect2 *self = (const Rect2 *)p_self;
const Vector2 *from = (const Vector2 *)p_from;
const Vector2 *to = (const Vector2 *)p_to;
Vector2 *pos = (Vector2 *)r_pos;
return self->intersects_segment(*from, *to, pos);
}
pandemonium_bool GDAPI pandemonium_rect2_intersects_segment_pos_normal(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_from, const pandemonium_vector2 *p_to, pandemonium_vector2 *r_pos, pandemonium_vector2 *r_normal) {
const Rect2 *self = (const Rect2 *)p_self;
const Vector2 *from = (const Vector2 *)p_from;
const Vector2 *to = (const Vector2 *)p_to;
Vector2 *pos = (Vector2 *)r_pos;
Vector2 *normal = (Vector2 *)r_normal;
return self->intersects_segment(*from, *to, pos, normal);
}
pandemonium_bool GDAPI pandemonium_rect2_encloses(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b) {
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *b = (const Rect2 *)p_b;
@ -69,6 +139,14 @@ pandemonium_rect2 GDAPI pandemonium_rect2_clip(const pandemonium_rect2 *p_self,
return dest;
}
pandemonium_rect2 GDAPI pandemonium_rect2_intersection(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_rect) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *rect = (const Rect2 *)p_rect;
*((Rect2 *)&dest) = self->intersection(*rect);
return dest;
}
pandemonium_rect2 GDAPI pandemonium_rect2_merge(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
@ -83,14 +161,24 @@ pandemonium_bool GDAPI pandemonium_rect2_has_point(const pandemonium_rect2 *p_se
return self->has_point(*point);
}
pandemonium_bool GDAPI pandemonium_rect2_is_equal_approx(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_rect) {
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *rect = (const Rect2 *)p_rect;
return self->is_equal_approx(*rect);
}
pandemonium_rect2 GDAPI pandemonium_rect2_grow(const pandemonium_rect2 *p_self, const pandemonium_real p_by) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Rect2 *)&dest) = self->grow(p_by);
return dest;
}
void GDAPI pandemonium_rect2_grow_by(pandemonium_rect2 *p_self, const pandemonium_real p_by) {
Rect2 *self = (Rect2 *)p_self;
self->grow_by(p_by);
}
pandemonium_rect2 GDAPI pandemonium_rect2_grow_individual(const pandemonium_rect2 *p_self, const pandemonium_real p_left, const pandemonium_real p_top, const pandemonium_real p_right, const pandemonium_real p_bottom) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
@ -98,6 +186,13 @@ pandemonium_rect2 GDAPI pandemonium_rect2_grow_individual(const pandemonium_rect
return dest;
}
pandemonium_rect2 GDAPI pandemonium_rect2_grow_side(const pandemonium_rect2 *p_self, const pandemonium_int p_side, const pandemonium_real p_amount) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Rect2 *)&dest) = self->grow_side(static_cast<Side>(p_side), p_amount);
return dest;
}
pandemonium_rect2 GDAPI pandemonium_rect2_grow_margin(const pandemonium_rect2 *p_self, const pandemonium_int p_margin, const pandemonium_real p_by) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
@ -105,13 +200,6 @@ pandemonium_rect2 GDAPI pandemonium_rect2_grow_margin(const pandemonium_rect2 *p
return dest;
}
pandemonium_rect2 GDAPI pandemonium_rect2_abs(const pandemonium_rect2 *p_self) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Rect2 *)&dest) = self->abs();
return dest;
}
pandemonium_rect2 GDAPI pandemonium_rect2_expand(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_to) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
@ -120,40 +208,46 @@ pandemonium_rect2 GDAPI pandemonium_rect2_expand(const pandemonium_rect2 *p_self
return dest;
}
void GDAPI pandemonium_rect2_expand_to(pandemonium_rect2 *p_self, const pandemonium_vector2 *p_vector) {
Rect2 *self = (Rect2 *)p_self;
const Vector2 *vector = (const Vector2 *)p_vector;
self->expand_to(*vector);
}
pandemonium_rect2 GDAPI pandemonium_rect2_abs(const pandemonium_rect2 *p_self) {
pandemonium_rect2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Rect2 *)&dest) = self->abs();
return dest;
}
pandemonium_vector2 GDAPI pandemonium_rect2_get_support(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_normal) {
pandemonium_vector2 dest;
const Rect2 *self = (const Rect2 *)p_self;
const Vector2 *normal = (const Vector2 *)p_normal;
*((Vector2 *)&dest) = self->get_support(*normal);
return dest;
}
void GDAPI pandemonium_rect2_set_end(pandemonium_rect2 *p_self, const pandemonium_vector2 *p_end) {
Rect2 *self = (Rect2 *)p_self;
const Vector2 *end = (const Vector2 *)p_end;
self->set_end(*end);
}
pandemonium_vector2 GDAPI pandemonium_rect2_get_end(const pandemonium_rect2 *p_self) {
pandemonium_vector2 dest;
const Rect2 *self = (const Rect2 *)p_self;
*((Vector2 *)&dest) = self->get_end();
return dest;
}
pandemonium_bool GDAPI pandemonium_rect2_operator_equal(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b) {
const Rect2 *self = (const Rect2 *)p_self;
const Rect2 *b = (const Rect2 *)p_b;
return *self == *b;
}
pandemonium_vector2 GDAPI pandemonium_rect2_get_position(const pandemonium_rect2 *p_self) {
pandemonium_vector2 dest;
Vector2 *d = (Vector2 *)&dest;
const Rect2 *self = (const Rect2 *)p_self;
*d = self->get_position();
return dest;
}
pandemonium_vector2 GDAPI pandemonium_rect2_get_size(const pandemonium_rect2 *p_self) {
pandemonium_vector2 dest;
Vector2 *d = (Vector2 *)&dest;
const Rect2 *self = (const Rect2 *)p_self;
*d = self->get_size();
return dest;
}
void GDAPI pandemonium_rect2_set_position(pandemonium_rect2 *p_self, const pandemonium_vector2 *p_pos) {
Rect2 *self = (Rect2 *)p_self;
const Vector2 *position = (const Vector2 *)p_pos;
self->set_position(*position);
}
void GDAPI pandemonium_rect2_set_size(pandemonium_rect2 *p_self, const pandemonium_vector2 *p_size) {
Rect2 *self = (Rect2 *)p_self;
const Vector2 *size = (const Vector2 *)p_size;
self->set_size(*size);
}
pandemonium_string GDAPI pandemonium_rect2_as_string(const pandemonium_rect2 *p_self) {
pandemonium_string ret;
const Rect2 *self = (const Rect2 *)p_self;

View File

@ -51,6 +51,7 @@ typedef struct pandemonium_rect2 {
#include <gdn/gdnative.h>
#include <gdn/vector2.h>
#include <gdn/transform2d.h>
#ifdef __cplusplus
extern "C" {
@ -64,46 +65,46 @@ void GDAPI pandemonium_rect2_set_size(pandemonium_rect2 *p_self, const pandemoni
pandemonium_real GDAPI pandemonium_rect2_get_area(const pandemonium_rect2 *p_self);
//_FORCE_INLINE_ Vector2 get_center() const { return position + (size * 0.5f); }
pandemonium_vector2 GDAPI pandemonium_rect2_get_center(const pandemonium_rect2 *p_self);
pandemonium_bool GDAPI pandemonium_rect2_intersects(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b);
//inline real_t distance_to(const Vector2 &p_point) const {
pandemonium_real GDAPI pandemonium_rect2_distance_to(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_point);
//bool intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const;
pandemonium_bool GDAPI pandemonium_rect2_intersects_transformed(const pandemonium_rect2 *p_self, const pandemonium_transform2d *p_xform, const pandemonium_rect2 *p_rect);
//bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos = nullptr, Point2 *r_normal = nullptr) const;
pandemonium_bool GDAPI pandemonium_rect2_intersects_segment(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_from, const pandemonium_vector2 *p_to);
pandemonium_bool GDAPI pandemonium_rect2_intersects_segment_pos(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_from, const pandemonium_vector2 *p_to, pandemonium_vector2 *r_pos);
pandemonium_bool GDAPI pandemonium_rect2_intersects_segment_pos_normal(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_from, const pandemonium_vector2 *p_to, pandemonium_vector2 *r_pos, pandemonium_vector2 *r_normal);
pandemonium_bool GDAPI pandemonium_rect2_encloses(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b);
pandemonium_bool GDAPI pandemonium_rect2_has_no_area(const pandemonium_rect2 *p_self);
pandemonium_rect2 GDAPI pandemonium_rect2_clip(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b);
//inline Rect2 intersection(const Rect2 &p_rect) const {
pandemonium_rect2 GDAPI pandemonium_rect2_intersection(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_rect);
pandemonium_rect2 GDAPI pandemonium_rect2_merge(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b);
pandemonium_bool GDAPI pandemonium_rect2_has_point(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_point);
//bool is_equal_approx(const Rect2 &p_rect) const;
pandemonium_bool GDAPI pandemonium_rect2_is_equal_approx(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_rect);
pandemonium_bool GDAPI pandemonium_rect2_operator_equal(const pandemonium_rect2 *p_self, const pandemonium_rect2 *p_b);
pandemonium_rect2 GDAPI pandemonium_rect2_grow(const pandemonium_rect2 *p_self, const pandemonium_real p_by);
//inline void grow_by(real_t p_by) {
void GDAPI pandemonium_rect2_grow_by(pandemonium_rect2 *p_self, const pandemonium_real p_by);
pandemonium_rect2 GDAPI pandemonium_rect2_grow_margin(const pandemonium_rect2 *p_self, const pandemonium_int p_margin, const pandemonium_real p_by);
//inline Rect2 grow_side(Side p_side, real_t p_amount) const {
pandemonium_rect2 GDAPI pandemonium_rect2_grow_side(const pandemonium_rect2 *p_self, const pandemonium_int p_side, const pandemonium_real p_amount);
pandemonium_rect2 GDAPI pandemonium_rect2_grow_individual(const pandemonium_rect2 *p_self, const pandemonium_real p_left, const pandemonium_real p_top, const pandemonium_real p_right, const pandemonium_real p_bottom);
pandemonium_rect2 GDAPI pandemonium_rect2_expand(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_to);
//inline void expand_to(const Vector2 &p_vector) { //in place function for speed
void GDAPI pandemonium_rect2_expand_to(pandemonium_rect2 *p_self, const pandemonium_vector2 *p_vector);
pandemonium_rect2 GDAPI pandemonium_rect2_abs(const pandemonium_rect2 *p_self);
//Vector2 get_support(const Vector2 &p_normal) const {
pandemonium_vector2 GDAPI pandemonium_rect2_get_support(const pandemonium_rect2 *p_self, const pandemonium_vector2 *p_normal);
//_FORCE_INLINE_ bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const {
//_FORCE_INLINE_ void set_end(const Vector2 &p_end) {
//_FORCE_INLINE_ Vector2 get_end() const {
void GDAPI pandemonium_rect2_set_end(pandemonium_rect2 *p_self, const pandemonium_vector2 *p_end);
pandemonium_vector2 GDAPI pandemonium_rect2_get_end(const pandemonium_rect2 *p_self);
pandemonium_string GDAPI pandemonium_rect2_as_string(const pandemonium_rect2 *p_self);