From fb888ce8c256d14498547cf628ca4ef730e27258 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:34:01 -0400 Subject: [PATCH 01/15] Add Vector2:Angle(rhs) --- crates/lune-roblox/src/datatypes/types/vector2.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector2.rs b/crates/lune-roblox/src/datatypes/types/vector2.rs index 343fb706..c4028085 100644 --- a/crates/lune-roblox/src/datatypes/types/vector2.rs +++ b/crates/lune-roblox/src/datatypes/types/vector2.rs @@ -52,6 +52,9 @@ impl LuaUserData for Vector2 { fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) { // Methods + methods.add_method("Angle", |_, this, rhs: LuaUserDataRef| { + Ok(this.0.angle_between(rhs.0)) + }); methods.add_method("Cross", |_, this, rhs: LuaUserDataRef| { let this_v3 = Vec3::new(this.0.x, this.0.y, 0f32); let rhs_v3 = Vec3::new(rhs.0.x, rhs.0.y, 0f32); From b0f1a878b66664538513d4fb422a6739c323f3ed Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:35:34 -0400 Subject: [PATCH 02/15] Add Vector2:FuzzyEq(rhs) --- crates/lune-roblox/src/datatypes/types/vector2.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector2.rs b/crates/lune-roblox/src/datatypes/types/vector2.rs index c4028085..370df7b5 100644 --- a/crates/lune-roblox/src/datatypes/types/vector2.rs +++ b/crates/lune-roblox/src/datatypes/types/vector2.rs @@ -63,6 +63,14 @@ impl LuaUserData for Vector2 { methods.add_method("Dot", |_, this, rhs: LuaUserDataRef| { Ok(this.0.dot(rhs.0)) }); + methods.add_method( + "FuzzyEq", + |_, this, (rhs, epsilon): (LuaUserDataRef, f32)| { + let eq_x = (rhs.0.x - this.0.x).abs() <= epsilon; + let eq_y = (rhs.0.y - this.0.y).abs() <= epsilon; + Ok(eq_x && eq_y) + }, + ); methods.add_method( "Lerp", |_, this, (rhs, alpha): (LuaUserDataRef, f32)| { From bdffd3741b838561ed9796f9cb61b95b1bff133d Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:36:11 -0400 Subject: [PATCH 03/15] Add Vector2:Abs() --- crates/lune-roblox/src/datatypes/types/vector2.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector2.rs b/crates/lune-roblox/src/datatypes/types/vector2.rs index 370df7b5..82c80cfb 100644 --- a/crates/lune-roblox/src/datatypes/types/vector2.rs +++ b/crates/lune-roblox/src/datatypes/types/vector2.rs @@ -83,6 +83,7 @@ impl LuaUserData for Vector2 { methods.add_method("Min", |_, this, rhs: LuaUserDataRef| { Ok(Vector2(this.0.min(rhs.0))) }); + methods.add_method("Abs", |_, this, ()| Ok(Vector2(this.0.abs()))); // Metamethods methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); From 1f35f02e152a8f01115916d1bbbc89b767f1cb16 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:36:39 -0400 Subject: [PATCH 04/15] Add Vector2:Ceil() --- crates/lune-roblox/src/datatypes/types/vector2.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector2.rs b/crates/lune-roblox/src/datatypes/types/vector2.rs index 82c80cfb..cbf220ad 100644 --- a/crates/lune-roblox/src/datatypes/types/vector2.rs +++ b/crates/lune-roblox/src/datatypes/types/vector2.rs @@ -84,6 +84,7 @@ impl LuaUserData for Vector2 { Ok(Vector2(this.0.min(rhs.0))) }); methods.add_method("Abs", |_, this, ()| Ok(Vector2(this.0.abs()))); + methods.add_method("Ceil", |_, this, ()| Ok(Vector2(this.0.ceil()))); // Metamethods methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); From 3170b2a1bc4855b04bfe448d19894454af9ac6a5 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:37:08 -0400 Subject: [PATCH 05/15] Add Vector2:Floor() --- crates/lune-roblox/src/datatypes/types/vector2.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector2.rs b/crates/lune-roblox/src/datatypes/types/vector2.rs index cbf220ad..ca76b489 100644 --- a/crates/lune-roblox/src/datatypes/types/vector2.rs +++ b/crates/lune-roblox/src/datatypes/types/vector2.rs @@ -85,6 +85,7 @@ impl LuaUserData for Vector2 { }); methods.add_method("Abs", |_, this, ()| Ok(Vector2(this.0.abs()))); methods.add_method("Ceil", |_, this, ()| Ok(Vector2(this.0.ceil()))); + methods.add_method("Floor", |_, this, ()| Ok(Vector2(this.0.floor()))); // Metamethods methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); From 431b4eaac903a56af5b7cc63911e8573f8e704dd Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:37:28 -0400 Subject: [PATCH 06/15] Add Vector2:Sign() --- crates/lune-roblox/src/datatypes/types/vector2.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector2.rs b/crates/lune-roblox/src/datatypes/types/vector2.rs index ca76b489..2248530c 100644 --- a/crates/lune-roblox/src/datatypes/types/vector2.rs +++ b/crates/lune-roblox/src/datatypes/types/vector2.rs @@ -86,6 +86,7 @@ impl LuaUserData for Vector2 { methods.add_method("Abs", |_, this, ()| Ok(Vector2(this.0.abs()))); methods.add_method("Ceil", |_, this, ()| Ok(Vector2(this.0.ceil()))); methods.add_method("Floor", |_, this, ()| Ok(Vector2(this.0.floor()))); + methods.add_method("Sign", |_, this, ()| Ok(Vector2(this.0.signum()))); // Metamethods methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); From 4d44b34865b141a955df2d9ac66a21c4621fddd5 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:38:05 -0400 Subject: [PATCH 07/15] Add Vector3:Abs() --- crates/lune-roblox/src/datatypes/types/vector3.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector3.rs b/crates/lune-roblox/src/datatypes/types/vector3.rs index 11bcd4a4..0dce3007 100644 --- a/crates/lune-roblox/src/datatypes/types/vector3.rs +++ b/crates/lune-roblox/src/datatypes/types/vector3.rs @@ -133,6 +133,7 @@ impl LuaUserData for Vector3 { methods.add_method("Min", |_, this, rhs: LuaUserDataRef| { Ok(Vector3(this.0.min(rhs.0))) }); + methods.add_method("Abs", |_, this, ()| Ok(Vector3(this.0.abs()))); // Metamethods methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); From 24b28e5c2f80505acf4880236e77012c78905862 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:38:24 -0400 Subject: [PATCH 08/15] Add Vector3:Ceil() --- crates/lune-roblox/src/datatypes/types/vector3.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector3.rs b/crates/lune-roblox/src/datatypes/types/vector3.rs index 0dce3007..fc319650 100644 --- a/crates/lune-roblox/src/datatypes/types/vector3.rs +++ b/crates/lune-roblox/src/datatypes/types/vector3.rs @@ -134,6 +134,7 @@ impl LuaUserData for Vector3 { Ok(Vector3(this.0.min(rhs.0))) }); methods.add_method("Abs", |_, this, ()| Ok(Vector3(this.0.abs()))); + methods.add_method("Ceil", |_, this, ()| Ok(Vector3(this.0.ceil()))); // Metamethods methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); From 1a0492d0b55d983395eb208181437b59509cbba1 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:38:47 -0400 Subject: [PATCH 09/15] Add Vector3:Floor() --- crates/lune-roblox/src/datatypes/types/vector3.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector3.rs b/crates/lune-roblox/src/datatypes/types/vector3.rs index fc319650..fe1e0cdf 100644 --- a/crates/lune-roblox/src/datatypes/types/vector3.rs +++ b/crates/lune-roblox/src/datatypes/types/vector3.rs @@ -135,6 +135,7 @@ impl LuaUserData for Vector3 { }); methods.add_method("Abs", |_, this, ()| Ok(Vector3(this.0.abs()))); methods.add_method("Ceil", |_, this, ()| Ok(Vector3(this.0.ceil()))); + methods.add_method("Floor", |_, this, ()| Ok(Vector3(this.0.floor()))); // Metamethods methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); From 42b736edad776975b9ebb0c83fa36bccad496a38 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Tue, 16 Jul 2024 01:38:56 -0400 Subject: [PATCH 10/15] Add Vector3:Sign() --- crates/lune-roblox/src/datatypes/types/vector3.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/lune-roblox/src/datatypes/types/vector3.rs b/crates/lune-roblox/src/datatypes/types/vector3.rs index fe1e0cdf..c976c543 100644 --- a/crates/lune-roblox/src/datatypes/types/vector3.rs +++ b/crates/lune-roblox/src/datatypes/types/vector3.rs @@ -136,6 +136,7 @@ impl LuaUserData for Vector3 { methods.add_method("Abs", |_, this, ()| Ok(Vector3(this.0.abs()))); methods.add_method("Ceil", |_, this, ()| Ok(Vector3(this.0.ceil()))); methods.add_method("Floor", |_, this, ()| Ok(Vector3(this.0.floor()))); + methods.add_method("Sign", |_, this, ()| Ok(Vector3(this.0.signum()))); // Metamethods methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); From 96e54685ee7b19f63eba2a2faaa2e0f88198b1b4 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Fri, 19 Jul 2024 19:27:40 -0400 Subject: [PATCH 11/15] Add Vector2 method tests covering this PR --- tests/roblox/datatypes/Vector2.luau | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/roblox/datatypes/Vector2.luau b/tests/roblox/datatypes/Vector2.luau index 1ed391ee..0e501613 100644 --- a/tests/roblox/datatypes/Vector2.luau +++ b/tests/roblox/datatypes/Vector2.luau @@ -42,4 +42,14 @@ assert(Vector2.new(2, 4) / 2 == Vector2.new(1, 2)) assert(Vector2.new(7, 15) // Vector2.new(3, 7) == Vector2.new(2, 2)) assert(Vector2.new(3, 7) // 2 == Vector2.new(1, 3)) --- TODO: Vector math +-- Vector math methods +assert(Vector2.new(-1, -2):Abs() == Vector2.new(1, 2)) +assert(Vector2.new(-1.7, 2):Sign() == Vector2.new(-1, 1)) +assert(Vector2.new(-1.9, 2.1):Ceil() == Vector2.new(-1, 3)) +assert(Vector2.new(-1.1, 2.99):Floor() == Vector2.new(-2, 2)) + +assert(Vector2.new(1, 2):FuzzyEq(Vector2.new(1 - 1e-6, 2 + 1e-6))) +assert(Vector2.new(1, 2):Angle(Vector2.new(3, 4))) + +local angle = Vector2.new(1, 1):Angle(Vector2.new(-1, 1)) +assert(math.abs(angle - (math.pi / 2)) < 1e-5) From e58bcc0c2a340fdfa57dd806418d8bfd62d39abf Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Fri, 19 Jul 2024 19:27:45 -0400 Subject: [PATCH 12/15] Add Vector3 method tests covering this PR --- tests/roblox/datatypes/Vector3.luau | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/roblox/datatypes/Vector3.luau b/tests/roblox/datatypes/Vector3.luau index 4a4b7453..0f01b9fb 100644 --- a/tests/roblox/datatypes/Vector3.luau +++ b/tests/roblox/datatypes/Vector3.luau @@ -45,4 +45,8 @@ assert(Vector3.new(2, 4, 8) / 2 == Vector3.new(1, 2, 4)) assert(Vector3.new(7, 11, 15) // Vector3.new(3, 5, 7) == Vector3.new(2, 2, 2)) assert(Vector3.new(3, 5, 7) // 2 == Vector3.new(1, 2, 3)) --- TODO: Vector math +-- Vector math methods +assert(Vector3.new(-1, -2, -3):Abs() == Vector3.new(1, 2, 3)) +assert(Vector3.new(-1.7, 2, -3):Sign() == Vector3.new(-1, 1, -1)) +assert(Vector3.new(-1.9, 2.1, 3.5):Ceil() == Vector3.new(-1, 3, 4)) +assert(Vector3.new(-1.1, 2.99, 3.5):Floor() == Vector3.new(-2, 2, 3)) From 362c850b2dfea2f2c1b695b75cbd5b4bdb812987 Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Fri, 19 Jul 2024 19:31:23 -0400 Subject: [PATCH 13/15] Cleanup extra assertion --- tests/roblox/datatypes/Vector2.luau | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/roblox/datatypes/Vector2.luau b/tests/roblox/datatypes/Vector2.luau index 0e501613..83f81f24 100644 --- a/tests/roblox/datatypes/Vector2.luau +++ b/tests/roblox/datatypes/Vector2.luau @@ -49,7 +49,6 @@ assert(Vector2.new(-1.9, 2.1):Ceil() == Vector2.new(-1, 3)) assert(Vector2.new(-1.1, 2.99):Floor() == Vector2.new(-2, 2)) assert(Vector2.new(1, 2):FuzzyEq(Vector2.new(1 - 1e-6, 2 + 1e-6))) -assert(Vector2.new(1, 2):Angle(Vector2.new(3, 4))) local angle = Vector2.new(1, 1):Angle(Vector2.new(-1, 1)) assert(math.abs(angle - (math.pi / 2)) < 1e-5) From 83067d4ec1e99717169abf5647119b822df5c4cb Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Fri, 19 Jul 2024 19:53:01 -0400 Subject: [PATCH 14/15] Pass epsilon to Vector2:FuzzyEq() --- tests/roblox/datatypes/Vector2.luau | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/roblox/datatypes/Vector2.luau b/tests/roblox/datatypes/Vector2.luau index 83f81f24..523ba942 100644 --- a/tests/roblox/datatypes/Vector2.luau +++ b/tests/roblox/datatypes/Vector2.luau @@ -48,7 +48,8 @@ assert(Vector2.new(-1.7, 2):Sign() == Vector2.new(-1, 1)) assert(Vector2.new(-1.9, 2.1):Ceil() == Vector2.new(-1, 3)) assert(Vector2.new(-1.1, 2.99):Floor() == Vector2.new(-2, 2)) -assert(Vector2.new(1, 2):FuzzyEq(Vector2.new(1 - 1e-6, 2 + 1e-6))) +assert(Vector2.new(1, 2):FuzzyEq(Vector2.new(1 - 1e-6, 2 + 1e-6), 1e-5)) +assert(not Vector2.new(1, 2):FuzzyEq(Vector2.new(1.2, 2), 0.1)) local angle = Vector2.new(1, 1):Angle(Vector2.new(-1, 1)) assert(math.abs(angle - (math.pi / 2)) < 1e-5) From 7ed75b6ac50aef15f6b779c9ad379f47522584da Mon Sep 17 00:00:00 2001 From: ZachCurtis <31259055+ZachCurtis@users.noreply.github.com> Date: Fri, 19 Jul 2024 19:53:27 -0400 Subject: [PATCH 15/15] Add Vector3:FuzzyEq() method test --- tests/roblox/datatypes/Vector3.luau | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/roblox/datatypes/Vector3.luau b/tests/roblox/datatypes/Vector3.luau index 0f01b9fb..723e3abf 100644 --- a/tests/roblox/datatypes/Vector3.luau +++ b/tests/roblox/datatypes/Vector3.luau @@ -50,3 +50,5 @@ assert(Vector3.new(-1, -2, -3):Abs() == Vector3.new(1, 2, 3)) assert(Vector3.new(-1.7, 2, -3):Sign() == Vector3.new(-1, 1, -1)) assert(Vector3.new(-1.9, 2.1, 3.5):Ceil() == Vector3.new(-1, 3, 4)) assert(Vector3.new(-1.1, 2.99, 3.5):Floor() == Vector3.new(-2, 2, 3)) + +assert(Vector3.new(1, 2, 3):FuzzyEq(Vector3.new(1 - 1e-6, 2 + 1e-6, 3 + 1e-6), 1e-5))