Skip to content

Commit 227fdda

Browse files
committed
Vectors: Default, missing Vector2 constants, documentation
1 parent 3ad9b65 commit 227fdda

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

gdnative-core/src/core_types/vector2.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::IsEqualApprox;
22
use glam::Vec2;
33
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
44

5-
#[derive(Copy, Clone, Debug, PartialEq)]
5+
#[derive(Copy, Clone, Debug, PartialEq, Default)]
66
#[repr(C)]
77
pub struct Vector2 {
88
pub x: f32,
@@ -13,6 +13,27 @@ pub struct Vector2 {
1313
///
1414
/// See the official [`Godot documentation`](https://docs.godotengine.org/en/3.1/classes/class_vector2.html).
1515
impl Vector2 {
16+
/// The zero vector.
17+
pub const ZERO: Vector2 = Vector2::new(0.0, 0.0);
18+
19+
/// A vector with all components set to 1. Typically used for scaling.
20+
pub const ONE: Vector2 = Vector2::new(1.0, 1.0);
21+
22+
/// A vector with all components set to +infinity.
23+
pub const INF: Vector2 = Vector2::new(f32::INFINITY, f32::INFINITY);
24+
25+
/// Unit vector in -X direction.
26+
pub const LEFT: Vector2 = Vector2::new(-1.0, 0.0);
27+
28+
/// Unit vector in +X direction.
29+
pub const RIGHT: Vector2 = Vector2::new(1.0, 0.0);
30+
31+
/// Unit vector in -Y direction (the Y axis points down in 2D).
32+
pub const UP: Vector2 = Vector2::new(0.0, -1.0);
33+
34+
/// Unit vector in +Y direction (the Y axis points down in 2D).
35+
pub const DOWN: Vector2 = Vector2::new(0.0, 1.0);
36+
1637
/// Constructs a new Vector2 from the given x and y.
1738
#[inline]
1839
pub const fn new(x: f32, y: f32) -> Self {
@@ -455,7 +476,7 @@ mod tests {
455476
V::new(-1.2, 0.8),
456477
V::new(1.2, 10.3),
457478
V::new(-5.4, 4.2),
458-
0.2
479+
0.2,
459480
))
460481
);
461482

@@ -464,7 +485,7 @@ mod tests {
464485
V::new(-3.7, 2.1),
465486
V::new(5.4, -8.5),
466487
V::new(-10.8, -6.6),
467-
0.6
488+
0.6,
468489
))
469490
);
470491
}

gdnative-core/src/core_types/vector3.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::IsEqualApprox;
33
use glam::Vec3A;
44
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
55

6-
#[derive(Copy, Clone, Debug, PartialEq)]
6+
#[derive(Copy, Clone, Debug, PartialEq, Default)]
77
#[repr(C)]
88
pub struct Vector3 {
99
pub x: f32,
@@ -23,14 +23,31 @@ pub enum Axis {
2323
///
2424
/// See the official [`Godot documentation`](https://docs.godotengine.org/en/3.1/classes/class_vector3.html).
2525
impl Vector3 {
26+
/// The zero vector.
2627
pub const ZERO: Self = Self::new(0.0, 0.0, 0.0);
28+
29+
/// A vector with all components set to 1. Typically used for scaling.
2730
pub const ONE: Self = Self::new(1.0, 1.0, 1.0);
31+
32+
/// A vector with all components set to +infinity.
2833
pub const INF: Self = Self::new(f32::INFINITY, f32::INFINITY, f32::INFINITY);
34+
35+
/// Unit vector in -X direction.
2936
pub const LEFT: Self = Self::new(-1.0, 0.0, 0.0);
37+
38+
/// Unit vector in +X direction.
3039
pub const RIGHT: Self = Self::new(1.0, 0.0, 0.0);
40+
41+
/// Unit vector in +Y direction.
3142
pub const UP: Self = Self::new(0.0, 1.0, 0.0);
43+
44+
/// Unit vector in -Y direction.
3245
pub const DOWN: Self = Self::new(0.0, -1.0, 0.0);
46+
47+
/// Unit vector in -Z direction.
3348
pub const FORWARD: Self = Self::new(0.0, 0.0, -1.0);
49+
50+
/// Unit vector in +Z direction.
3451
pub const BACK: Self = Self::new(0.0, 0.0, 1.0);
3552

3653
/// Returns a Vector3 with the given components.

0 commit comments

Comments
 (0)