From 536a2291de424661dc33312cbea9e7d060da8fc6 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:05:48 -0700 Subject: [PATCH 01/15] vector tests pt1 --- .../conditions/CondIsVectorNormalized.java | 1 - .../expressions/ExprVectorArithmetic.java | 2 +- .../expressions/ExprVectorCylindrical.java | 2 +- .../conditions/CondIsVectorNormalized.sk | 4 +++ .../effects/EffVectorRotateAroundAnother.sk | 21 ++++++++++++ .../syntaxes/effects/EffVectorRotateXYZ.sk | 11 +++++++ .../expressions/ExprVectorAngleBetween.sk | 15 +++++++++ .../expressions/ExprVectorArithmetic.sk | 16 +++++++++ .../expressions/ExprVectorBetweenLocations.sk | 15 +++++++++ .../expressions/ExprVectorCrossProduct.sk | 15 +++++++++ .../expressions/ExprVectorCylindrical.sk | 6 ++++ .../syntaxes/expressions/ExprVectorDotProduct | 33 +++++++++++++++++++ 12 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 src/test/skript/tests/syntaxes/conditions/CondIsVectorNormalized.sk create mode 100644 src/test/skript/tests/syntaxes/effects/EffVectorRotateAroundAnother.sk create mode 100644 src/test/skript/tests/syntaxes/effects/EffVectorRotateXYZ.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorAngleBetween.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorArithmetic.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorBetweenLocations.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorCrossProduct.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorCylindrical.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct diff --git a/src/main/java/ch/njol/skript/conditions/CondIsVectorNormalized.java b/src/main/java/ch/njol/skript/conditions/CondIsVectorNormalized.java index c47f1289b3e..a93d02afa19 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsVectorNormalized.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsVectorNormalized.java @@ -32,7 +32,6 @@ @Description("Checks whether a vector is normalized i.e. length of 1") @Examples("vector of player's location is normalized") @Since("2.5.1") -@RequiredPlugins("Minecraft 1.13.2+") public class CondIsVectorNormalized extends PropertyCondition { static { diff --git a/src/main/java/ch/njol/skript/expressions/ExprVectorArithmetic.java b/src/main/java/ch/njol/skript/expressions/ExprVectorArithmetic.java index 41c81c2d8d4..312b1d15b32 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprVectorArithmetic.java +++ b/src/main/java/ch/njol/skript/expressions/ExprVectorArithmetic.java @@ -44,7 +44,7 @@ "set {_v} to {_v} ** {_v}", "set {_v} to {_v} // {_v}" }) -@Since("2.2-desecond8") +@Since("2.2-dev28") public class ExprVectorArithmetic extends SimpleExpression { private enum Operator { diff --git a/src/main/java/ch/njol/skript/expressions/ExprVectorCylindrical.java b/src/main/java/ch/njol/skript/expressions/ExprVectorCylindrical.java index 40cd9edd963..27499c7a5de 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprVectorCylindrical.java +++ b/src/main/java/ch/njol/skript/expressions/ExprVectorCylindrical.java @@ -47,7 +47,7 @@ public class ExprVectorCylindrical extends SimpleExpression { static { Skript.registerExpression(ExprVectorCylindrical.class, Vector.class, ExpressionType.SIMPLE, - "[a] [new] cylindrical vector [(from|with)] [radius] %number%, [yaw] %number%(,| and) [height] %number%"); + "[a] [new] cylindrical vector [(from|with)] [radius] %number%, [yaw] %number%(,[ and]| and) [height] %number%"); } @SuppressWarnings("null") diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsVectorNormalized.sk b/src/test/skript/tests/syntaxes/conditions/CondIsVectorNormalized.sk new file mode 100644 index 00000000000..618ffa599f3 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsVectorNormalized.sk @@ -0,0 +1,4 @@ +test "normalized vector": + assert vector(0,1,0) is normalized with "vector(0,1,0) not recognized as normal" + assert vector(1,0,0) is normalized with "vector(1,0,0) not recognized as normal" + assert vector(1,2,3) is not normalized with "vector(1,2,3) recognized as normal" diff --git a/src/test/skript/tests/syntaxes/effects/EffVectorRotateAroundAnother.sk b/src/test/skript/tests/syntaxes/effects/EffVectorRotateAroundAnother.sk new file mode 100644 index 00000000000..07d21ec5730 --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffVectorRotateAroundAnother.sk @@ -0,0 +1,21 @@ +test "vector rotate around vector": + set {_x} to vector(1, 0, 0) + set {_y} to vector(0, 1, 0) + set {_z} to vector(0, 0, 1) + + set {_v} to {_x} + rotate {_v} around {_y} by -90 degrees + assert {_v} is {_z} with "rotate around y vector failed (expected %{_z}%, got %{_v}%)" + + rotate {_v} around {_x} by -90 degrees + assert {_v} is {_y} with "rotate around x vector failed (expected %{_y}%, got %{_v}%)" + + rotate {_v} around {_z} by -90 degrees + assert {_v} is {_x} with "rotate around z vector failed (expected %{_x}%, got %{_v}%)" + + rotate {_v} around vector(1, 1, 1) by 180 degrees + assert {_v} is vector(-1/3, 2/3, 2/3) with "rotate around non-orthogonal vector failed (expected %vector(-1/3, 2/3, 2/3)%, got %{_v}%)" + + set {_v} to vector(2, 0, 0) + rotate {_v} around vector(0, 10, 0) by 90 degrees + assert {_v} is vector(0, 0, -2) with "rotate around non-unit vector failed (expected %vector(0, 0, -2)%, got %{_v}%)" diff --git a/src/test/skript/tests/syntaxes/effects/EffVectorRotateXYZ.sk b/src/test/skript/tests/syntaxes/effects/EffVectorRotateXYZ.sk new file mode 100644 index 00000000000..72adc840f8f --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffVectorRotateXYZ.sk @@ -0,0 +1,11 @@ +test "vector rotate around axis": + + set {_v} to vector(1, 1, 1) + rotate {_v} around y axis by 90 degrees + assert {_v} is vector(1, 1, -1) with "rotate around y vector failed (expected %vector(1, 1, -1)%, got %{_v}%)" + + rotate {_v} around x axis by -90 degrees + assert {_v} is vector(1, -1, -1) with "rotate around x vector failed (expected %vector(1, -1, -1)%, got %{_v}%)" + + rotate {_v} around z axis by -90 degrees + assert {_v} is vector(-1, -1, -1) with "rotate around z vector failed (expected %vector(-1, -1, -1)%, got %{_v}%)" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorAngleBetween.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorAngleBetween.sk new file mode 100644 index 00000000000..54b845558ff --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorAngleBetween.sk @@ -0,0 +1,15 @@ +test "angle between vectors": + set {_x} to vector(1,0,0) + set {_y} to vector(0,1,0) + assert angle between vectors {_x} and {_y} is 90 with "angle between x and y vectors is not 90" + + rotate {_x} around {_y} by 90 + assert angle between vectors {_x} and {_y} is 90 with "angle between vectors changed after rotation around one another" + + set vector length of {_x} to 2 + assert angle between vectors {_x} and {_y} is 90 with "angle between vectors changed after changing length of one" + + assert angle between vector(1, 0, 0) and vector(-1, 0, 0) is 180 with "angle between opposite vectors is not 180" + assert angle between {_x} and {_x} is 0 with "angle between same vectors is not 0" + + # note: add a NaN check for zero vectors once isNaN is added diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorArithmetic.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorArithmetic.sk new file mode 100644 index 00000000000..3d1324b04cc --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorArithmetic.sk @@ -0,0 +1,16 @@ +test "vector arithmetic": + assert vector(0, 0, 0) ++ vector(1, 1, 1) is vector(1, 1, 1) with "vector addition failed (expected %vector(1, 1, 1)%, got %vector(0, 0, 0) ++ vector(1, 1, 1)%)" + assert vector(1, 1, 1) -- vector(1, 1, 1) is vector(0, 0, 0) with "vector subtraction failed (expected %vector(0, 0, 0)%, got %vector(1, 1, 1) -- vector(1, 1, 1)%)" + assert vector(1, 1, 2) ** vector(1, 2, 3) is vector(1, 2, 6) with "vector multiplication failed (expected %vector(1, 2, 6)%, got %vector(1, 1, 2) ** vector(1, 2, 3)%)" + assert vector(1, 2, 6) // vector(1, 2, 3) is vector(1, 1, 2) with "vector division failed (expected %vector(1, 1, 2)%, got %vector(1, 2, 6) // vector(1, 2, 3)%)" + + set {_v} to vector(0, 0, 0) ** random vector + assert {_v} is vector(0, 0, 0) with "zero vector multiplication failed (expected %vector(0, 0, 0)%, got %{_v}%)" + + set {_v} to vector(1, 0, 1) // vector(0, 0, 0) + set {_x} to x component of {_v} + set {_y} to y component of {_v} + set {_z} to z component of {_v} + assert {_x} is infinity value with "division by zero failed (x component) (expected infinity, got %{_x}%)" + # note: add check for NaN here once isNaN is implemented + assert {_z} is infinity value with "division by zero failed (z component) (expected infinity, got %{_z}%)" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorBetweenLocations.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorBetweenLocations.sk new file mode 100644 index 00000000000..dbaf58a6a9d --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorBetweenLocations.sk @@ -0,0 +1,15 @@ +test "vector between locations": + set {_world} to world("world") + set {_loc1} to location(0,0,0,{_world}) + set {_loc2} to location(10,10,10,{_world}) + set {_vec} to vector between {_loc1} and {_loc2} + assert {_vec} is vector(10,10,10) with "vector between locations in same world failed (expected %vector(10,10,10)%, got %{_vec}%)" + + set {_world2} to world("world_the_end") + assert {_world2} is set with "no end world found" + set {_loc3} to location(10,10,10,{_world2}) + set {_vec2} to vector between {_loc1} and {_loc3} + assert {_vec2} is vector(10,10,10) with "vector between locations in different worlds failed (expected %vector(10,10,10)%, got %{_vec2}%)" + + set {_vec3} to vector between {_loc1} and {_loc1} + assert {_vec3} is vector(0,0,0) with "vector between same locations failed (expected %vector(0,0,0)%, got %{_vec3}%)" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorCrossProduct.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorCrossProduct.sk new file mode 100644 index 00000000000..8686994bf21 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorCrossProduct.sk @@ -0,0 +1,15 @@ +test "cross product": + set {_v} to vector(1, 0, 0) + set {_w} to vector(0, 1, 0) + set {_u} to {_v} cross {_w} + assert {_u} is vector(0, 0, 1) with "cross product of basis vectors failed (expected %vector(0,0,1)%, got %{_u}%)" + + set {_v} to vector(1, 1, 1) + set {_w} to vector(1, 1, -1) + set {_u} to {_v} cross {_w} + assert {_u} is vector(-2, 2, 0) with "cross product of non-basis vectors failed (expected %vector(-2, 2, 0)%, got %{_u}%)" + + set {_v} to vector(1, 2, 3) + set {_w} to vector(1, 2, 3) + set {_u} to {_v} cross {_w} + assert {_u} is vector(0, 0, 0) with "cross product of parallel vectors failed (expected %vector(0, 0, 0)%, got %{_u}%)" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorCylindrical.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorCylindrical.sk new file mode 100644 index 00000000000..a809b9e5e1a --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorCylindrical.sk @@ -0,0 +1,6 @@ +test "cylindrical vector": + set {_v} to cylindrical vector with radius 1, yaw 0, and height 1 + assert {_v} is vector(0, 1, 1) with "failed to create cylindrical vector (expected %vector(0, 1, 1)%, got %{_v}%)" + + set {_v} to cylindrical vector with radius 1, yaw 45, and height 1 + assert {_v} is vector(sqrt(2)/-2, 1, sqrt(2)/2) with "failed to create cylindrical vector (expected %vector(sqrt(2)/-2, 1, sqrt(2)/2)%, got %{_v}%)" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct b/src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct new file mode 100644 index 00000000000..fcaa33b22ec --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct @@ -0,0 +1,33 @@ +test "cross product": + set {_v} to vector(1, 0, 0) + set {_w} to vector(0, 1, 0) + set {_u} to {_v} dot {_w} + assert {_u} is 0 with "dot product of orthogonal unit vectors failed (expected 0, got %{_u}%)" + + set {_v} to vector(-5, 0, 0) + set {_w} to vector(0, 0, 10) + set {_u} to {_v} dot {_w} + assert {_u} is 0 with "dot product of orthogonal non-unit vectors failed (expected 0, got %{_u}%)" + + set {_v} to vector(1, 0, 0) + set {_u} to {_v} dot {_v} + assert {_u} is 3 with "dot product of parallel unit vectors failed (expected 1, got %{_u}%)" + + set {_v} to vector(1, 1, 1) + set {_u} to {_v} dot {_v} + assert {_u} is 3 with "dot product of parallel non-unit vectors failed (expected 3, got %{_u}%)" + + set {_v} to vector(1, 0, 0) + set {_w} to vector(-1, 0, 0) + set {_u} to {_v} dot {_w} + assert {_u} is -1 with "dot product of anti-parallel unit vectors failed (expected -1, got %{_u}%)" + + set {_v} to vector(1, 1, 1) + set {_w} to vector(-1, -1, -1) + set {_u} to {_v} dot {_w} + assert {_u} is 3 with "dot product of anti-parallel non-unit vectors failed (expected -3, got %{_u}%)" + + set {_v} to vector(1, 0, 0) + set {_w} to vector(0, 0, 0) + set {_u} to {_v} dot {_w} + assert {_u} is 0 with "dot product of zero vector failed (expected 0, got %{_u}%)" From b6e6c55b3eb81a58b2687a0d85fe696f7b15d4d6 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Wed, 1 Nov 2023 10:24:40 +0000 Subject: [PATCH 02/15] Add test for vector random being within expected bounds. --- .../tests/syntaxes/expressions/ExprVectorRandom.sk | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorRandom.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorRandom.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorRandom.sk new file mode 100644 index 00000000000..886e96417df --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorRandom.sk @@ -0,0 +1,11 @@ +test "vector random": + loop 100 times: + set {_vector} to a random vector + assert {_vector} is set with "random vector creation failed" + assert {_vector} is not vector(0, 0, 0) with "random vector was non-normal zero" + assert x component of {_vector} is greater than or equal to -1 with "random vector x was too small" + assert y component of {_vector} is greater than or equal to -1 with "random vector y was too small" + assert z component of {_vector} is greater than or equal to -1 with "random vector z was too small" + assert x component of {_vector} is less than or equal to 1 with "random vector x was too large" + assert y component of {_vector} is less than or equal to 1 with "random vector y was too large" + assert z component of {_vector} is less than or equal to 1 with "random vector z was too large" From f425e83bac28b292fc17d8ce6d6d85f431c95eed Mon Sep 17 00:00:00 2001 From: Moderocky Date: Wed, 1 Nov 2023 10:31:06 +0000 Subject: [PATCH 03/15] Add XYZ vector test. --- .../tests/syntaxes/expressions/ExprVectorFromXYZ.sk | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorFromXYZ.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorFromXYZ.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorFromXYZ.sk new file mode 100644 index 00000000000..de6b7bfeaf0 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorFromXYZ.sk @@ -0,0 +1,11 @@ +test "vector from xyz": + assert (a new vector to 0, 0 and 0) is vector(0, 0, 0) with "zero vector creation failed" + loop 60 times: + set {_x} to a random number between -100 and 100 + set {_y} to a random number between -100 and 100 + set {_z} to a random number between -100 and 100 + set {_vector} to a new vector from {_x}, {_y}, {_z} + assert {_vector} is vector({_x}, {_y}, {_z}) with "randomly-created vector equality failed (expected %vector({_x}, {_y}, {_z})%, got %{_vector}%)" + set {_random} to a random vector + set {_vector} to a new vector from x component of {_random}, y component of {_random}, z component of {_random} + assert {_vector} is {_random} with "random vector to created component equality failed (expected %{_random}%, got %{_vector}%)" From 946fe2839ec049ef5e21d3148bb199a05051506a Mon Sep 17 00:00:00 2001 From: Moderocky Date: Thu, 2 Nov 2023 09:59:13 +0000 Subject: [PATCH 04/15] Add vector XYZ component test. --- .../tests/syntaxes/expressions/ExprVectorXYZ.sk | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorXYZ.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorXYZ.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorXYZ.sk new file mode 100644 index 00000000000..2691fa58975 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorXYZ.sk @@ -0,0 +1,16 @@ +test "vector xyz": + assert the x component of vector(0, 0, 0) is 0 with "x = 0 vector component failed" + assert the x component of vector(1, 0, 0) is 1 with "x = 1 vector component failed" + assert the y component of vector(1, 1, 0) is 1 with "y = 1 vector component failed" + assert the z component of vector(1, 1, 1) is 1 with "z = 1 vector component failed" + loop 60 times: + set {_x} to a random number between -100 and 100 + set {_y} to a random number between -100 and 100 + set {_z} to a random number between -100 and 100 + set {_vector} to vector({_x}, {_y}, {_z}) + assert the x component of {_vector} is {_x} with "randomly-created vector x equality failed (expected %{_x}%, got %x component of {_vector}%)" + assert the y component of {_vector} is {_y} with "randomly-created vector y equality failed (expected %{_y}%, got %y component of {_vector}%)" + assert the z component of {_vector} is {_z} with "randomly-created vector z equality failed (expected %{_z}%, got %z component of {_vector}%)" + set {_random} to a random vector + set {_vector} to a new vector from x component of {_random}, y component of {_random}, z component of {_random} + assert {_vector} is {_random} with "random vector to created component equality failed (expected %{_random}%, got %{_vector}%)" From 30a7d9ea65c92b1465e3e672cea0ed0a203c2598 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Thu, 2 Nov 2023 10:04:12 +0000 Subject: [PATCH 05/15] Add vector length test. --- .../tests/syntaxes/expressions/ExprVectorLength.sk | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorLength.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorLength.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorLength.sk new file mode 100644 index 00000000000..abdeaea72dd --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorLength.sk @@ -0,0 +1,11 @@ +test "vector length": + assert the normal length of vector(0, 0, 0) is 0 with "0-length vector check failed" + assert the standard length of vector(0, 1, 0) is 1 with "1-length vector check failed" + assert the vector length of vector(0, 0, 2) is 2 with "2-length vector check failed" + loop 60 times: + set {_x} to a random number between -100 and 100 + set {_y} to a random number between -100 and 100 + set {_z} to a random number between -100 and 100 + set {_vector} to vector({_x}, {_y}, {_z}) + set {_length} to sqrt(({_x} ^ 2) + ({_y} ^ 2) + ({_z} ^ 2)) + assert the normal length of {_vector} is {_length} with "randomly-created vector length failed (expected %{_length}%, got %normal length of {_vector}%)" From eff19692972898f90d2f797b965e399b7c0891f6 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Fri, 3 Nov 2023 09:01:29 +0000 Subject: [PATCH 06/15] Add vector normalise test. --- .../tests/syntaxes/expressions/ExprVectorNormalize.sk | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorNormalize.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorNormalize.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorNormalize.sk new file mode 100644 index 00000000000..43ce59e211b --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorNormalize.sk @@ -0,0 +1,11 @@ +test "vector normalize": + assert the standard length of vector(0, 1, 0) normalized is 1 with "1-length vector normalisation check failed" + assert the vector length of vector(0, 0, 2) normalized is 1 with "2-length vector normalisation check failed" + assert vector(0, 0, 2) normalized is vector(0, 0, 1) with "normalised vector component comparison failed" + assert vector(6, 6, 6) normalized is vector(1, 1, 1) normalized with "normalised vector comparison failed" + loop 60 times: + set {_x} to a random number between -100 and 100 + set {_y} to a random number between -100 and 100 + set {_z} to a random number between -100 and 100 + set {_vector} to vector({_x}, {_y}, {_z}) normalized + assert the normal length of {_vector} is 1 with "randomly-created vector normalisation failed (expected 1, got %normal length of {_vector}%)" From db5b5f361e12385680cffe1809cc048751eafbe9 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Fri, 3 Nov 2023 09:25:16 +0000 Subject: [PATCH 07/15] Add vector from yaw and pitch test. --- .../expressions/ExprVectorFromYawAndPitch.sk | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorFromYawAndPitch.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorFromYawAndPitch.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorFromYawAndPitch.sk new file mode 100644 index 00000000000..92d2a561207 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorFromYawAndPitch.sk @@ -0,0 +1,12 @@ +test "vector from yaw and pitch": + assert (a new vector from yaw 0 and pitch 0) is vector(0, 0, 1) with "zero-angle vector creation failed: %a new vector from yaw 0 and pitch 0%" + assert (a new vector from yaw 90 and pitch 0) is vector(-1, 0, 0) with "90-yaw vector creation failed: %a new vector from yaw 90 and pitch 0%" + assert (a new vector from yaw 180 and pitch 0) is vector(0, 0, -1) with "180-yaw vector creation failed: %a new vector from yaw 180 and pitch 0%" + assert (a new vector from yaw -90 and pitch 0) is vector(1, 0, 0) with "-90-yaw vector creation failed: %a new vector from yaw -90 and pitch 0%" + assert (a new vector from yaw 0 and pitch 90) is vector(0, -1, 0) with "90-pitch vector creation failed: %a new vector from yaw 0 and pitch 90%" + assert (a new vector from yaw 0 and pitch -90) is vector(0, 1, 0) with "-90-pitch vector creation failed: %a new vector from yaw 0 and pitch -90%" + loop 60 times: + set {_yaw} to a random number between -180 and 180 + set {_pitch} to a random number between -90 and 90 + set {_vector} to a new vector from yaw {_yaw} and pitch {_pitch} + assert the normal length of {_vector} is 1 with "randomly-created vector was non-normal (expected length 1, got %normal length of {_vector}%)" From fd2ab40c294d6803db18dfea8d68e810c8f0e305 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:33:28 -0700 Subject: [PATCH 08/15] Add vector of location test --- .../expressions/ExprVectorOfLocation.sk | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorOfLocation.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorOfLocation.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorOfLocation.sk new file mode 100644 index 00000000000..537d7175c3c --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorOfLocation.sk @@ -0,0 +1,22 @@ +test "vector of location": + set {_loc} to location(1,0,0,world "world") + set {_v} to vector of {_loc} + assert x component of {_v} is x coordinate of {_loc} with "vector/location x equality failed (expected %x coordinate of {_loc}%, got %x component of {_v}%)" + assert y component of {_v} is y coordinate of {_loc} with "vector/location y equality failed (expected %y coordinate of {_loc}%, got %y component of {_v}%)" + assert z component of {_v} is z coordinate of {_loc} with "vector/location z equality failed (expected %z coordinate of {_loc}%, got %z component of {_v}%)" + + set {_loc} to location(1,2,3,world "invalid world") + set {_v} to vector of {_loc} + assert x component of {_v} is x coordinate of {_loc} with "vector/location x equality failed when world is null (expected %x coordinate of {_loc}%, got %x component of {_v}%)" + assert y component of {_v} is y coordinate of {_loc} with "vector/location y equality failed when world is null (expected %y coordinate of {_loc}%, got %y component of {_v}%)" + assert z component of {_v} is z coordinate of {_loc} with "vector/location z equality failed when world is null (expected %z coordinate of {_loc}%, got %z component of {_v}%)" + + + set {_x} to random number between -10000 and 10000 + set {_y} to random number between -10000 and 10000 + set {_z} to random number between -10000 and 10000 + set {_loc} to location({_x}, {_y}, {_z},world "world") + set {_v} to vector of {_loc} + assert x component of {_v} is x coordinate of {_loc} with "random vector/location x equality failed (expected %x coordinate of {_loc}%, got %x component of {_v}%)" + assert y component of {_v} is y coordinate of {_loc} with "random vector/location y equality failed (expected %y coordinate of {_loc}%, got %y component of {_v}%)" + assert z component of {_v} is z coordinate of {_loc} with "random vector/location z equality failed (expected %z coordinate of {_loc}%, got %z component of {_v}%)" From 503252d5811e175b7c99f5a2ea88e39a94e4a496 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Sat, 4 Nov 2023 11:34:25 +0000 Subject: [PATCH 09/15] Add squared length test. --- .../syntaxes/expressions/ExprVectorSquaredLength.sk | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorSquaredLength.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorSquaredLength.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorSquaredLength.sk new file mode 100644 index 00000000000..748f0d10c14 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorSquaredLength.sk @@ -0,0 +1,11 @@ +test "vector squared length": + assert the squared length of vector(0, 0, 0) is 0 with "0-length vector check failed" + assert the squared length of vector(0, 1, 0) is 1 with "1-length vector check failed" + assert the squared length of vector(0, 0, 2) is 4 with "2-length vector check failed" + loop 60 times: + set {_x} to a random number between -100 and 100 + set {_y} to a random number between -100 and 100 + set {_z} to a random number between -100 and 100 + set {_vector} to vector({_x}, {_y}, {_z}) + set {_length} to ({_x} ^ 2) + ({_y} ^ 2) + ({_z} ^ 2) + assert the squared length of {_vector} is {_length} with "randomly-created vector length failed (expected %{_length}%, got %squared length of {_vector}%)" From 4cf1cc5120fb6148dac57c4859b4698b2352e462 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Sun, 5 Nov 2023 09:15:56 +0000 Subject: [PATCH 10/15] Add location vector offset test. --- .../expressions/ExprLocationVectorOffset.sk | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprLocationVectorOffset.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprLocationVectorOffset.sk b/src/test/skript/tests/syntaxes/expressions/ExprLocationVectorOffset.sk new file mode 100644 index 00000000000..d33bf64c7a3 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprLocationVectorOffset.sk @@ -0,0 +1,14 @@ +test "location vector offset": + set {_location} to the spawn of world "world" + set {_offset} to {_location} offset by vector(0, 0, 0) + assert {_offset} is {_location} with "no offset equality check failed" + assert the distance between {_offset} and {_location} is 0 with "0 offset check failed" + set {_offset} to {_location} offset by vector(0, 1, 0) + assert the distance between {_offset} and {_location} is 1 with "1 offset check failed" + loop 60 times: + set {_x} to a random number between -100 and 100 + set {_y} to a random number between -100 and 100 + set {_z} to a random number between -100 and 100 + set {_offset} to {_location} ~ vector({_x}, {_y}, {_z}) + set {_length} to the normal length of vector({_x}, {_y}, {_z}) + assert the distance between {_offset} and {_location} is {_length} with "randomly-created vector offset failed (expected %{_length}%, got %distance between {_offset} and {_location}%)" From 0f34a1e09c7dbb05d30ebbcf2a640fe2ae4804a1 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Tue, 7 Nov 2023 12:27:54 +0000 Subject: [PATCH 11/15] Add missing indefinite article to syntax. --- .../java/ch/njol/skript/expressions/ExprVectorSpherical.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprVectorSpherical.java b/src/main/java/ch/njol/skript/expressions/ExprVectorSpherical.java index 3507f8ab25a..c4cbd63026a 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprVectorSpherical.java +++ b/src/main/java/ch/njol/skript/expressions/ExprVectorSpherical.java @@ -47,7 +47,7 @@ public class ExprVectorSpherical extends SimpleExpression { static { Skript.registerExpression(ExprVectorSpherical.class, Vector.class, ExpressionType.SIMPLE, - "[new] spherical vector [(from|with)] [radius] %number%, [yaw] %number%(,| and) [pitch] %number%"); + "[a] [new] spherical vector [(from|with)] [radius] %number%, [yaw] %number%(,| and) [pitch] %number%"); } @SuppressWarnings("null") From 58c945ff8bbf5daf8ab068fad9680502aaaf69c7 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Tue, 7 Nov 2023 12:47:43 +0000 Subject: [PATCH 12/15] Add tests for spherical vectors. --- .../syntaxes/expressions/ExprVectorSpherical.sk | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprVectorSpherical.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorSpherical.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorSpherical.sk new file mode 100644 index 00000000000..a528c834d69 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorSpherical.sk @@ -0,0 +1,17 @@ +test "vector spherical": + set {_vector} to a new spherical vector 0, 0, 0 + assert the normal length of {_vector} is 0 with "zero-length vector had non-zero length" + assert {_vector} is vector(0, 0, 0) with "zero spherical vector was not zero vector" + loop 10 times: + set {_yaw} to a random number between -180 and 180 + set {_pitch} to a random number between -90 and 90 + set {_vector} to a new spherical vector with radius 0, yaw {_yaw} and pitch {_pitch} + assert the normal length of {_vector} is 0 with "random zero-length vector had non-zero length" + assert {_vector} is vector(0, 0, 0) with "random zero spherical vector was not zero vector" + assert (a new spherical vector 2, 0, -90) is vector(0, 2, 0) with "upwards 2-length vector equality failed" + assert (a new spherical vector 1, 0, 0) is vector(0, 0, 1) with "zero-angle vector creation failed: %a new vector from yaw 0 and pitch 0%" + assert (a new spherical vector 1, 90, 0) is vector(-1, 0, 0) with "90-yaw vector creation failed: %a new vector from yaw 90 and pitch 0%" + assert (a new spherical vector 1, 180, 0) is vector(0, 0, -1) with "180-yaw vector creation failed: %a new vector from yaw 180 and pitch 0%" + assert (a new spherical vector 1, -90, 0) is vector(1, 0, 0) with "-90-yaw vector creation failed: %a new vector from yaw -90 and pitch 0%" + assert (a new spherical vector 1, 0, 90) is vector(0, -1, 0) with "90-pitch vector creation failed: %a new vector from yaw 0 and pitch 90%" + assert (a new spherical vector 1, 0, -90) is vector(0, 1, 0) with "-90-pitch vector creation failed: %a new vector from yaw 0 and pitch -90%" From 7752d0188bc705b394786ae3514d23624f78c3a3 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Wed, 8 Nov 2023 10:20:44 +0000 Subject: [PATCH 13/15] Fix a little oopsie. --- .../{ExprVectorDotProduct => ExprVectorDotProduct.sk} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/test/skript/tests/syntaxes/expressions/{ExprVectorDotProduct => ExprVectorDotProduct.sk} (86%) diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct b/src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct.sk similarity index 86% rename from src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct rename to src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct.sk index fcaa33b22ec..e6b968d76dd 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorDotProduct.sk @@ -11,7 +11,7 @@ test "cross product": set {_v} to vector(1, 0, 0) set {_u} to {_v} dot {_v} - assert {_u} is 3 with "dot product of parallel unit vectors failed (expected 1, got %{_u}%)" + assert {_u} is 1 with "dot product of parallel unit vectors failed (expected 1, got %{_u}%)" set {_v} to vector(1, 1, 1) set {_u} to {_v} dot {_v} @@ -25,7 +25,7 @@ test "cross product": set {_v} to vector(1, 1, 1) set {_w} to vector(-1, -1, -1) set {_u} to {_v} dot {_w} - assert {_u} is 3 with "dot product of anti-parallel non-unit vectors failed (expected -3, got %{_u}%)" + assert {_u} is -3 with "dot product of anti-parallel non-unit vectors failed (expected -3, got %{_u}%)" set {_v} to vector(1, 0, 0) set {_w} to vector(0, 0, 0) From 7a40a6832156655acbf9410aaf371b8fede8a6b6 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Fri, 2 Feb 2024 20:28:54 +0100 Subject: [PATCH 14/15] Apply suggestions from code review Co-authored-by: Patrick Miller --- .../java/ch/njol/skript/expressions/ExprVectorCylindrical.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprVectorCylindrical.java b/src/main/java/ch/njol/skript/expressions/ExprVectorCylindrical.java index 27499c7a5de..773b1a50f09 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprVectorCylindrical.java +++ b/src/main/java/ch/njol/skript/expressions/ExprVectorCylindrical.java @@ -47,7 +47,7 @@ public class ExprVectorCylindrical extends SimpleExpression { static { Skript.registerExpression(ExprVectorCylindrical.class, Vector.class, ExpressionType.SIMPLE, - "[a] [new] cylindrical vector [(from|with)] [radius] %number%, [yaw] %number%(,[ and]| and) [height] %number%"); + "[a] [new] cylindrical vector [from|with] [radius] %number%, [yaw] %number%(,[ and]| and) [height] %number%"); } @SuppressWarnings("null") From 8bb243f9dfcaa049712a4f4cebf72dd731f58d0e Mon Sep 17 00:00:00 2001 From: sovde <10354869+sovdeeth@users.noreply.github.com> Date: Fri, 2 Feb 2024 20:36:49 +0100 Subject: [PATCH 15/15] test updates --- .../skript/expressions/ExprVectorArithmetic.java | 1 - .../syntaxes/expressions/ExprVectorAngleBetween.sk | 3 ++- .../syntaxes/expressions/ExprVectorArithmetic.sk | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprVectorArithmetic.java b/src/main/java/ch/njol/skript/expressions/ExprVectorArithmetic.java index a890974023f..3cb57f8d10c 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprVectorArithmetic.java +++ b/src/main/java/ch/njol/skript/expressions/ExprVectorArithmetic.java @@ -47,7 +47,6 @@ "set {_v} to {_v} ** {_v}", "set {_v} to {_v} // {_v}" }) -@Since("2.2-dev28") @Since("2.2-dev28, 2.8.0 (deprecation)") @Deprecated public class ExprVectorArithmetic extends SimpleExpression { diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorAngleBetween.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorAngleBetween.sk index 54b845558ff..f0a3a624af7 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprVectorAngleBetween.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorAngleBetween.sk @@ -12,4 +12,5 @@ test "angle between vectors": assert angle between vector(1, 0, 0) and vector(-1, 0, 0) is 180 with "angle between opposite vectors is not 180" assert angle between {_x} and {_x} is 0 with "angle between same vectors is not 0" - # note: add a NaN check for zero vectors once isNaN is added + assert isNaN(angle between vector(0, 0, 0) and vector(0, 1, 0)) is true with "angle between zero vector is not NaN" + diff --git a/src/test/skript/tests/syntaxes/expressions/ExprVectorArithmetic.sk b/src/test/skript/tests/syntaxes/expressions/ExprVectorArithmetic.sk index 3d1324b04cc..cafd8d43457 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprVectorArithmetic.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprVectorArithmetic.sk @@ -1,16 +1,16 @@ test "vector arithmetic": - assert vector(0, 0, 0) ++ vector(1, 1, 1) is vector(1, 1, 1) with "vector addition failed (expected %vector(1, 1, 1)%, got %vector(0, 0, 0) ++ vector(1, 1, 1)%)" - assert vector(1, 1, 1) -- vector(1, 1, 1) is vector(0, 0, 0) with "vector subtraction failed (expected %vector(0, 0, 0)%, got %vector(1, 1, 1) -- vector(1, 1, 1)%)" - assert vector(1, 1, 2) ** vector(1, 2, 3) is vector(1, 2, 6) with "vector multiplication failed (expected %vector(1, 2, 6)%, got %vector(1, 1, 2) ** vector(1, 2, 3)%)" - assert vector(1, 2, 6) // vector(1, 2, 3) is vector(1, 1, 2) with "vector division failed (expected %vector(1, 1, 2)%, got %vector(1, 2, 6) // vector(1, 2, 3)%)" + assert vector(0, 0, 0) + vector(1, 1, 1) is vector(1, 1, 1) with "vector addition failed (expected %vector(1, 1, 1)%, got %vector(0, 0, 0) ++ vector(1, 1, 1)%)" + assert vector(1, 1, 1) - vector(1, 1, 1) is vector(0, 0, 0) with "vector subtraction failed (expected %vector(0, 0, 0)%, got %vector(1, 1, 1) -- vector(1, 1, 1)%)" + assert vector(1, 1, 2) * vector(1, 2, 3) is vector(1, 2, 6) with "vector multiplication failed (expected %vector(1, 2, 6)%, got %vector(1, 1, 2) ** vector(1, 2, 3)%)" + assert vector(1, 2, 6) / vector(1, 2, 3) is vector(1, 1, 2) with "vector division failed (expected %vector(1, 1, 2)%, got %vector(1, 2, 6) // vector(1, 2, 3)%)" - set {_v} to vector(0, 0, 0) ** random vector + set {_v} to vector(0, 0, 0) * random vector assert {_v} is vector(0, 0, 0) with "zero vector multiplication failed (expected %vector(0, 0, 0)%, got %{_v}%)" - set {_v} to vector(1, 0, 1) // vector(0, 0, 0) + set {_v} to vector(1, 0, 1) / vector(0, 0, 0) set {_x} to x component of {_v} set {_y} to y component of {_v} set {_z} to z component of {_v} assert {_x} is infinity value with "division by zero failed (x component) (expected infinity, got %{_x}%)" - # note: add check for NaN here once isNaN is implemented + assert isNaN({_y}) is true with "division by zero failed (y component) (expected NaN, got %{_y}%" assert {_z} is infinity value with "division by zero failed (z component) (expected infinity, got %{_z}%)"