-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mirroring and rotating vectors
- Loading branch information
1 parent
835f25d
commit 941d2ff
Showing
7 changed files
with
466 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/quality/GodotSharpSome.Drawing2D.Tests/Vector2DExtensionTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
namespace GodotSharpSome.Drawing2D.Tests; | ||
|
||
public class Vector2DExtensionTest | ||
{ | ||
[Fact] | ||
public void MirrorX() | ||
{ | ||
var mirrored = new Vector2(3, 1).MirrorX(1f); | ||
|
||
Assert.Equal(-1f, mirrored.X, 6); | ||
Assert.Equal(1f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void MirrorY() | ||
{ | ||
var mirrored = new Vector2(1, 3).MirrorY(1f); | ||
|
||
Assert.Equal(1f, mirrored.X, 6); | ||
Assert.Equal(-1f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void MirrorByDirection_ToVectorParallelToXAxis() | ||
{ | ||
var mirrored = new Vector2(1, 1).MirrorByDirection(Vector2.Right); | ||
|
||
Assert.Equal(1f, mirrored.X, 6); | ||
Assert.Equal(-1f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void MirrorByDirection_ToVectorParallelToYAxis() | ||
{ | ||
var mirrored = new Vector2(1, 1).MirrorByDirection(Vector2.Down); | ||
|
||
Assert.Equal(-1f, mirrored.X, 6); | ||
Assert.Equal(1f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void MirrorByDirection_ToXEqualYLine() | ||
{ | ||
var mirrored = new Vector2(1, 0).MirrorByDirection(Vector2.One * 3); | ||
|
||
Assert.Equal(0, mirrored.X, 6); | ||
Assert.Equal(1, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void MirrorByDirection_ToVectorParallelToXAxisWithOffset() | ||
{ | ||
var mirrored = new Vector2(2, 2).MirrorByDirection(Vector2.One, Vector2.Right); | ||
|
||
Assert.Equal(2f, mirrored.X, 6); | ||
Assert.Equal(0f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void MirrorByDirection_ToVectorParallelToYAxisWithOffset() | ||
{ | ||
var mirrored = new Vector2(2, 2).MirrorByDirection(Vector2.One, Vector2.Down); | ||
|
||
Assert.Equal(0f, mirrored.X, 6); | ||
Assert.Equal(2f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void MirrorByPoints_ToLineParallelToX() | ||
{ | ||
var mirrored = new Vector2(2, 2).MirrorByPoints(Vector2.One, Vector2.One + Vector2.Right); | ||
|
||
Assert.Equal(2f, mirrored.X, 6); | ||
Assert.Equal(0f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void MirrorByPoints_ToLineParallelToY() | ||
{ | ||
var mirrored = new Vector2(2, 2).MirrorByPoints(Vector2.One, Vector2.One + Vector2.Down); | ||
|
||
Assert.Equal(0f, mirrored.X, 6); | ||
Assert.Equal(2f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void Rotated_AroundOrigin() | ||
{ | ||
var mirrored = Vector2.Right.Rotated(Mathf.Pi); | ||
|
||
Assert.Equal(-1f, mirrored.X, 6); | ||
Assert.Equal(0f, mirrored.Y, 6); | ||
} | ||
|
||
[Fact] | ||
public void Rotated_AroundPoint() | ||
{ | ||
var mirrored = Vector2.One.Rotated(Vector2.Right, Mathf.Pi); | ||
|
||
Assert.Equal(1f, mirrored.X, 6); | ||
Assert.Equal(-1f, mirrored.Y, 6); | ||
} | ||
} |
Oops, something went wrong.