Skip to content

Commit 21401a1

Browse files
Merge #218
218: godot-core: builtin: reimplement Rect2i to reduce need of inner usage r=Bromeon a=yannick-was-taken Addresses part of #209 . Only doing `Rect2i` for now, so that suggestions only have to be applied once, instead of four times ;) The implementations are tested (regular case + edge case where applicable) including an itest that checks equivalence between the inner type's fns and the implemented fns. Documentation is mostly taken from Godot's docs for Rect2i, with little changes here and there. There are a bunch of FIXMEs that need to be resolved before this is mergable: Godot's rect2i.h prints errors in some cases when the rect size is negative. In accordance with what I believe to be a design principle of gdext, the equivalent fns panic in that case (compare to `cast`/`try_cast`: default is to assume and panic?). There could be `_unchecked` fns that likely should be marked unsafe, as though they would not introduce memory unsafety, they would result in "Garbage In / Garbage Out", which in Rust usually is considered unsafe, as the safe bet would be to prevent the Garbage In situation via typing, or at least make it return `Option<Garbage Out>`. The Option approach could be used here as well, but would change the type's API as opposed to what it is in GdScript. So please provide input on those FIXMEs as to what you think should be done here. Co-authored-by: yannick-was-taken <[email protected]>
2 parents afbd2cd + d7e0e81 commit 21401a1

File tree

13 files changed

+781
-45
lines changed

13 files changed

+781
-45
lines changed

godot-core/src/builtin/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ mod real_mod {
212212
/// A 4-dimensional vector from [`glam`]. Using a floating-point format compatible with [`real`].
213213
pub type RVec4 = glam::Vec4;
214214

215-
/// A 2x2 column-major matrix from [`glam`]. Using a floating-point format compatible with [`real`].
215+
/// A 2x2 column-major matrix from [`glam`]. Using a floating-point format compatible with [`real`].
216216
pub type RMat2 = glam::Mat2;
217217
/// A 3x3 column-major matrix from [`glam`]. Using a floating-point format compatible with [`real`].
218218
pub type RMat3 = glam::Mat3;
@@ -279,7 +279,7 @@ mod real_mod {
279279
/// A 4-dimensional vector from [`glam`]. Using a floating-point format compatible with [`real`].
280280
pub type RVec4 = glam::DVec4;
281281

282-
/// A 2x2 column-major matrix from [`glam`]. Using a floating-point format compatible with [`real`].
282+
/// A 2x2 column-major matrix from [`glam`]. Using a floating-point format compatible with [`real`].
283283
pub type RMat2 = glam::DMat2;
284284
/// A 3x3 column-major matrix from [`glam`]. Using a floating-point format compatible with [`real`].
285285
pub type RMat3 = glam::DMat3;
@@ -302,6 +302,8 @@ pub use crate::real;
302302
pub(crate) use real_mod::*;
303303
pub use real_mod::{consts as real_consts, real};
304304

305+
pub(crate) use glam::{IVec2, IVec3, IVec4};
306+
305307
/// A macro to coerce float-literals into the real type. Mainly used where
306308
/// you'd normally use a suffix to specity the type, such as `115.0f32`.
307309
///
@@ -330,6 +332,7 @@ macro_rules! real {
330332
/// The side of a [`Rect2`] or [`Rect2i`].
331333
///
332334
/// _Godot equivalent: `@GlobalScope.Side`_
335+
#[derive(Copy, Clone)]
333336
#[repr(C)]
334337
pub enum RectSide {
335338
Left = 0,

0 commit comments

Comments
 (0)