public void TestEquals() { float x = 1, y = 2; float x2 = 3, y2 = 4; Vector2D v1 = new Vector2D(x, y); Vector2D v2 = new Vector2D(x, y); Vector2D v3 = new Vector2D(x2, y2); //Test IEquatable Equals Assert.IsTrue(v1.Equals(v2), "Test IEquatable equals"); Assert.IsFalse(v1.Equals(v3), "Test IEquatable equals"); //Test object equals override Assert.IsTrue(v1.Equals((object) v2), "Tests object equals"); Assert.IsFalse(v1.Equals((object) v3), "Tests object equals"); //Test op equals Assert.IsTrue(v1 == v2, "Testing OpEquals"); Assert.IsFalse(v1 == v3, "Testing OpEquals"); //Test op not equals Assert.IsTrue(v1 != v3, "Testing OpNotEquals"); Assert.IsFalse(v1 != v2, "Testing OpNotEquals"); }
public void TestEquals() { float x = 1, y = 2; float x2 = 3, y2 = 4; Vector2D v1 = new Vector2D(x, y); Vector2D v2 = new Vector2D(x, y); Vector2D v3 = new Vector2D(x2, y2); //Test IEquatable Equals Assert.IsTrue(v1.Equals(v2), "Test IEquatable equals"); Assert.IsFalse(v1.Equals(v3), "Test IEquatable equals"); //Test object equals override Assert.IsTrue(v1.Equals((object)v2), "Tests object equals"); Assert.IsFalse(v1.Equals((object) v3), "Tests object equals"); //Test op equals Assert.IsTrue(v1 == v2, "Testing OpEquals"); Assert.IsFalse(v1 == v3, "Testing OpEquals"); //Test op not equals Assert.IsTrue(v1 != v3, "Testing OpNotEquals"); Assert.IsFalse(v1 != v2, "Testing OpNotEquals"); }
public void Vector2EqualsTest() { Vector2D <float> a = new Vector2D <float>(1.0f, 2.0f); Vector2D <float> b = new Vector2D <float>(1.0f, 2.0f); // case 1: compare between same values object obj = b; bool expected = true; bool actual = a.Equals(obj); Assert.Equal(expected, actual); // case 2: compare between different values b.X = 10.0f; obj = b; expected = false; actual = a.Equals(obj); Assert.Equal(expected, actual); // case 3: compare between different types. obj = new Quaternion <float>(); expected = false; actual = a.Equals(obj); Assert.Equal(expected, actual); // case 3: compare against null. obj = null; expected = false; actual = a.Equals(obj); Assert.Equal(expected, actual); }
public void TestEquals() { Vector2D vector = new Vector2D(1, 2); Assert.IsTrue(vector.Equals(new Vector2D(1, 2))); Assert.IsFalse(vector.Equals(new Vector2D(2, 1))); Assert.IsFalse(vector.Equals("(1, 2)")); Assert.IsFalse(vector.Equals(null)); }
public void TestEquals() { Vector2D v0 = new Vector2D(678.0, 234.8); Vector2D v1 = new Vector2D(678.0, 234.8); Vector2D v2 = new Vector2D(67.0, 234.8); Vector2D v3 = new Vector2D(678.0, 24.8); Assert.IsTrue(v0.Equals(v0)); Assert.IsTrue(v0.Equals(v1)); Assert.IsFalse(v0.Equals(v2)); Assert.IsFalse(v0.Equals(v3)); Assert.IsFalse(v0.Equals(v0.ToString())); }
public void NullVector() { var vector = new Vector2D(); const Vector3D nullVector = null; Assert.IsFalse(vector.Equals(nullVector)); }
public void TestPositiveClamp() { Vector2D aVector = new Vector2D(7, 7); aVector.Clamp(); Assert.IsTrue(aVector.Equals(new Vector2D(1, 1))); }
public void DifferentDimensions() { var vector2D = new Vector2D(); var vector3D = new Vector3D(); Assert.IsFalse(vector2D.Equals(vector3D)); }
public void EqualsTest1() { var v = new Vector2D(-9, 3); var w = new Vector2D(-9, 3 + delta * 0.5); Assert.IsTrue(v.Equals(w, delta)); }
public void EqualityComparerThrowsExceptionOnNegativeTolerance() { var v1 = new Vector2D(0, 0); var v2 = new Vector2D(1, 1); Assert.Throws <ArgumentException>(() => v1.Equals(v2, -0.01)); }
public void Rotate() { Vector2D TestVector = new Vector2D(1, 0); TestVector.Rotate((double)System.Math.PI / 2); Assert.IsTrue(TestVector.Equals(new Vector2D(0, 1), .001f)); }
public void TestNegativeClamp() { Vector2D aVector = new Vector2D(-7, -7); aVector.Clamp(); Assert.IsTrue(aVector.Equals(new Vector2D(-1, -1))); }
public void different_components_are_not_equal() { var a = new Vector2D(5.0, -1.1); var b = new Vector2D(-1.1, 5.0); var c = new Vector2D(5.0, 5.0); var d = new Vector2D(-1.1, -1.1); var e = new Vector2D(); Assert.False(a.Equals((object)b)); Assert.False(b.Equals((object)a)); Assert.False(a.Equals((object)c)); Assert.False(c.Equals((object)a)); Assert.False(a.Equals((object)d)); Assert.False(d.Equals((object)a)); Assert.False(a.Equals((object)e)); Assert.False(e.Equals((object)a)); }
public void same_components_are_equal() { var a = new Vector2D(5.0, -1.1); var b = new Vector2D(5.0, -1.1); Assert.True(a.Equals((object)b)); Assert.True(b.Equals((object)a)); }
public void Vector2EqualsTest1() { Vector2D <float> a = new Vector2D <float>(1.0f, 2.0f); Vector2D <float> b = new Vector2D <float>(1.0f, 2.0f); // case 1: compare between same values bool expected = true; bool actual = a.Equals(b); Assert.Equal(expected, actual); // case 2: compare between different values b.X = 10.0f; expected = false; actual = a.Equals(b); Assert.Equal(expected, actual); }
public void Equals() { Assert.AreNotEqual(v1, v2); Assert.AreEqual(v1, new Vector2D(1, 2)); Assert.IsTrue(v1 == new Vector2D(1, 2)); Assert.IsTrue(v1 != v2); Assert.IsTrue(v1.Equals((object)new Vector2D(1, 2))); }
public void Vector2EqualsNanTest() { Vector2D <float> a = new Vector2D <float>(float.NaN, 0); Vector2D <float> b = new Vector2D <float>(0, float.NaN); Assert.False(a == Vector2D <float> .Zero); Assert.False(b == Vector2D <float> .Zero); Assert.True(a != Vector2D <float> .Zero); Assert.True(b != Vector2D <float> .Zero); Assert.False(a.Equals(Vector2D <float> .Zero)); Assert.False(b.Equals(Vector2D <float> .Zero)); // Counterintuitive result - IEEE rules for NaN comparison are weird! Assert.False(a.Equals(a)); Assert.False(b.Equals(b)); }
public void EqualsTest1() { Vector2D a = new Vector2D(1, 2); Vector2D b = new Vector2D(1, 2); Assert.IsTrue(a.Equals(b)); Assert.IsTrue(b.Equals(a)); //Vector2D c = new Vector2D(2, 3); //Assert.IsFalse(c.Equals(null)); }
public void DifferentValues() { var vector1 = new Vector2D(1, 0); var vector2 = new Vector2D(2, 0); Assert.IsFalse(vector1.Equals(vector2)); Assert.AreEqual(1, vector1.X); Assert.AreEqual(2, vector2.X); }
static void AssertEquals(Vector2D expected, Vector2D actual) { bool isEqual = expected.Equals(actual); if (!isEqual) { TestContext.WriteLine($"Expected {expected} but actual is {actual}"); } Assert.That(isEqual); }
public void EqualsMethodTest() { // Arrange Vector2D vector1; Vector2D vector2; // Act vector1 = new Vector2D(1, 2); vector2 = new Vector2D(3, 4); // Assert Assert.IsFalse(vector1.Equals(vector2), "Error, the equals method doesn't work anymore."); }
public void EqualsTest() { Vector2D a = new Vector2D(1, 2); Vector2D b = new Vector2D(1, 2); Assert.IsTrue(a.Equals(b)); Assert.IsTrue(b.Equals(a)); Vector2D c = new Vector2D(2, 3); Vector2D d = new Vector2D(3, 2); Assert.IsFalse(c.Equals(d)); Assert.IsFalse(d.Equals(c)); }
public void SameValues() { var vector1 = new Vector2D(1, 2); var vector2 = new Vector2D(1, 2); Assert.IsTrue(vector1.Equals(vector2)); Assert.AreEqual(1, vector1.X); Assert.AreEqual(2, vector1.Y); Assert.AreEqual(1, vector2.X); Assert.AreEqual(2, vector2.Y); }
public void FindPath(LevelTileType typeOfStartTile) { Vector2D startPoint = FindTile(typeOfStartTile); if (startPoint.Equals(Vector2D.Unused)) { throw new StartPointNotFound(); } var tileCoordinates = new Vector2D[Width * Height]; for (int lineIndex = 0; lineIndex < Height; lineIndex++) { for (int symbolIndex = 0; symbolIndex < Width; symbolIndex++) { tileCoordinates[symbolIndex + lineIndex * Width] = new Vector2D(symbolIndex, lineIndex); } } }
public static bool Equals(ref ALVector2D left, ref ALVector2D right) { return(left.Angular == right.Angular && Vector2D.Equals(ref left.Linear, ref right.Linear)); }
public static bool operator !=(ALVector2D left, ALVector2D right) { return(!(left.Angular == right.Angular && Vector2D.Equals(ref left.Linear, ref right.Linear))); }
// Lighting 2D public static List <Vector2D> GetConvexHull(List <Vector2D> points) { //If we have just 3 points, then they are the convex hull, so return those if (points.Count == 3) { //These might not be ccw, and they may also be colinear return(points); } //If fewer points, then we cant create a convex hull if (points.Count < 3) { return(null); } //The list with points on the convex hull List <Vector2D> convexHull = new List <Vector2D>(); //Step 1. Find the vertex with the smallest x coordinate //If several have the same x coordinate, find the one with the smallest z Vector2D startVertex = points[0]; Vector2 startPos = startVertex.ToVector2(); for (int i = 1; i < points.Count; i++) { Vector2 testPos = points[i].ToVector2(); //Because of precision issues, we use Mathf.Approximately to test if the x positions are the same if (testPos.x < startPos.x || (Mathf.Approximately(testPos.x, startPos.x) && testPos.y < startPos.y)) { startVertex = points[i]; startPos = startVertex.ToVector2(); } } //This vertex is always on the convex hull convexHull.Add(startVertex); points.Remove(startVertex); //Step 2. Loop to generate the convex hull Vector2D currentPoint = convexHull[0]; //Store colinear points here - better to create this list once than each loop List <Vector2D> colinearPoints = new List <Vector2D>(); int counter = 0; while (true) { //After 2 iterations we have to add the start position again so we can terminate the algorithm //Cant use convexhull.count because of colinear points, so we need a counter if (counter == 2) { points.Add(convexHull[0]); } //Pick next point randomly Vector2D nextPoint = points[Random.Range(0, points.Count)]; //To 2d space so we can see if a point is to the left is the vector ab Vector2 a = currentPoint.ToVector2(); Vector2 b = nextPoint.ToVector2(); //Test if there's a point to the right of ab, if so then it's the new b for (int i = 0; i < points.Count; i++) { //Dont test the point we picked randomly if (points[i].Equals(nextPoint)) { continue; } Vector2 c = points[i].ToVector2(); //Where is c in relation to a-b // < 0 -> to the right // = 0 -> on the line // > 0 -> to the left float relation = IsAPointLeftOfVectorOrOnTheLine(a, b, c); //Colinear points //Cant use exactly 0 because of floating point precision issues //This accuracy is smallest possible, if smaller points will be missed if we are testing with a plane float accuracy = 0.00001f; if (relation < accuracy && relation > -accuracy) { colinearPoints.Add(points[i]); } //To the right = better point, so pick it as next point on the convex hull else if (relation < 0f) { nextPoint = points[i]; b = nextPoint.ToVector2(); //Clear colinear points colinearPoints.Clear(); } //To the left = worse point so do nothing } //If we have colinear points if (colinearPoints.Count > 0) { colinearPoints.Add(nextPoint); //Sort this list, so we can add the colinear points in correct order colinearPoints = colinearPoints.OrderBy(n => Vector3.SqrMagnitude(n.ToVector2() - currentPoint.ToVector2())).ToList(); convexHull.AddRange(colinearPoints); currentPoint = colinearPoints[colinearPoints.Count - 1]; //Remove the points that are now on the convex hull for (int i = 0; i < colinearPoints.Count; i++) { points.Remove(colinearPoints[i]); } colinearPoints.Clear(); } else { convexHull.Add(nextPoint); points.Remove(nextPoint); currentPoint = nextPoint; } //Have we found the first point on the hull? If so we have completed the hull if (currentPoint.Equals(convexHull[0])) { //Then remove it because it is the same as the first point, and we want a convex hull with no duplicates convexHull.RemoveAt(convexHull.Count - 1); break; } counter += 1; } return(convexHull); }
public static bool Equals(ref BoundingRectangle rect1, ref BoundingRectangle rect2) { return(Vector2D.Equals(ref rect1.Min, ref rect2.Min) && Vector2D.Equals(ref rect1.Max, ref rect2.Max)); }
public void testEqualsVector2D() { Assert.IsFalse(testVector.Equals(new Vector2D(6.0d, 5.0d))); Assert.IsTrue(testVector.Equals(new Vector2D(3.0d, 4.0d))); }
public void DrawArrowRoundStyle(SimpleImage img, uint clr, Vector2D start, Vector2D end, ArrowHeadStyle startHead, ArrowHeadStyle endHead, float hookLength, float lineThickness) { if (hookLength <= 0f) { DrawRoundLine(img, start, end, lineThickness, clr); return; } // If the start and end points are the same then it is a degenerate arrow. We'll just fill a // circle in this case. if (start.Equals(end)) { FillCircle(img, clr, new Circle2D(start, lineThickness / 2f)); return; } // For the round style arrows, we essentially just have to render a series of round lines. // What we DON'T want to do is draw one for the arrow "body" and then additional ones for // the hooks at the end. This is because there will be duplicate blending near the ends and // it won't look as good. Vector2D dirNorm = Vector2D.Normalize(end - start); Vector2D perpNorm = Vector2D.Normalize((start - end).GetPerpendicular()); List<Stadium> slist = new List<Stadium>(); // We always need the main line slist.Add(new Stadium(start, end, lineThickness / 2f)); if (ArrowHeadStyle.BothHooks == startHead || ArrowHeadStyle.UpperHookOnly == startHead) { slist.Add(new Stadium(start, start + (dirNorm * hookLength) + (perpNorm * hookLength), lineThickness / 2f)); } if (ArrowHeadStyle.BothHooks == startHead || ArrowHeadStyle.LowerHookOnly == startHead) { slist.Add(new Stadium(start, start + (dirNorm * hookLength) - (perpNorm * hookLength), lineThickness / 2f)); } if (ArrowHeadStyle.BothHooks == endHead || ArrowHeadStyle.UpperHookOnly == endHead) { slist.Add(new Stadium(end, end - (dirNorm * hookLength) + (perpNorm * hookLength), lineThickness / 2f)); } if (ArrowHeadStyle.BothHooks == endHead || ArrowHeadStyle.LowerHookOnly == endHead) { slist.Add(new Stadium(end, end - (dirNorm * hookLength) - (perpNorm * hookLength), lineThickness / 2f)); } Stadium[] stads = slist.ToArray(); // Soften radius, hard-coded for now float sr = 2f; FillStadiums(img, clr, stads, sr); }
public void EqualityComparerThrowsExceptionOnNegativeTolerance() { var v1 = new Vector2D(0, 0); var v2 = new Vector2D(1, 1); Assert.Throws<ArgumentException>(() => v1.Equals(v2, -0.01)); }
public static bool Equals(ref LineSegment line1, ref LineSegment line2) { return(Vector2D.Equals(ref line1.Vertex1, ref line2.Vertex1) && Vector2D.Equals(ref line1.Vertex2, ref line2.Vertex2)); }
public static bool Equals(ref Ray ray1, ref Ray ray2) { return(Vector2D.Equals(ref ray1.Origin, ref ray2.Origin) && Vector2D.Equals(ref ray1.Direction, ref ray2.Direction)); }
public void TestEquals() { Vector2D a = new Vector2D(1.0, 2.0); Vector2D b = new Vector2D(4.0, 5.0); Vector2D c = new Vector2D(1.0, 2.0); Assert.IsTrue(a.Equals(c)); Assert.IsTrue(c.Equals(a)); Assert.IsTrue(a == c); Assert.IsTrue(c == a); Assert.IsFalse(c != a); Assert.IsFalse(c != a); Assert.IsFalse(a.Equals(b)); Assert.IsFalse(b.Equals(a)); Assert.IsFalse(a == b); Assert.IsFalse(b == a); Assert.IsTrue(a != b); Assert.IsTrue(b != a); object objA = a; object objB = b; object objC = c; Assert.IsTrue(a.Equals(objA)); Assert.IsTrue(a.Equals(objC)); Assert.IsFalse(a.Equals(objB)); Assert.IsTrue(objA.Equals(objC)); Assert.IsFalse(objA.Equals(objB)); Assert.IsFalse(a.Equals(null)); Assert.IsFalse(a.Equals(5)); }