A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System;
5using NUnit.Framework;
6using osu.Framework.Graphics;
7using osu.Framework.Graphics.Primitives;
8using osuTK;
9
10namespace osu.Framework.Tests.Primitives
11{
12 [TestFixture]
13 public class Vector2ExtensionsTest
14 {
15 [TestCase(true)]
16 [TestCase(false)]
17 public void TestArrayOrientation(bool clockwise)
18 {
19 var vertices = new[]
20 {
21 new Vector2(0, 1),
22 Vector2.One,
23 new Vector2(1, 0),
24 Vector2.Zero
25 };
26
27 if (!clockwise)
28 Array.Reverse(vertices);
29
30 float orientation = Vector2Extensions.GetOrientation(vertices);
31
32 Assert.That(orientation, Is.EqualTo(clockwise ? 2 : -2).Within(0.001));
33 }
34
35 [TestCase(true)]
36 [TestCase(false)]
37 public void TestQuadOrientation(bool normalised)
38 {
39 Quad quad = normalised
40 ? new Quad(Vector2.Zero, new Vector2(1, 0), new Vector2(0, 1), Vector2.One)
41 : new Quad(new Vector2(0, 1), Vector2.One, Vector2.Zero, new Vector2(1, 0));
42
43 float orientation = Vector2Extensions.GetOrientation(quad.GetVertices());
44
45 Assert.That(orientation, Is.EqualTo(normalised ? 2 : -2).Within(0.001));
46 }
47 }
48}