Skip to content

Commit

Permalink
Merge #218
Browse files Browse the repository at this point in the history
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 <yannick-was-taken@posteo.de>
  • Loading branch information
bors[bot] and yannick-was-taken authored Apr 12, 2023
2 parents afbd2cd + d7e0e81 commit 21401a1
Show file tree
Hide file tree
Showing 13 changed files with 781 additions and 45 deletions.
7 changes: 5 additions & 2 deletions godot-core/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mod real_mod {
/// A 4-dimensional vector from [`glam`]. Using a floating-point format compatible with [`real`].
pub type RVec4 = glam::Vec4;

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

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

pub(crate) use glam::{IVec2, IVec3, IVec4};

/// A macro to coerce float-literals into the real type. Mainly used where
/// you'd normally use a suffix to specity the type, such as `115.0f32`.
///
Expand Down Expand Up @@ -330,6 +332,7 @@ macro_rules! real {
/// The side of a [`Rect2`] or [`Rect2i`].
///
/// _Godot equivalent: `@GlobalScope.Side`_
#[derive(Copy, Clone)]
#[repr(C)]
pub enum RectSide {
Left = 0,
Expand Down
Loading

0 comments on commit 21401a1

Please sign in to comment.