Browse Source

quadrangle2D now uses 4 explicit vectors instead of vector array

Alexander Hendrich 10 years ago
parent
commit
56dedfe8b8
2 changed files with 15 additions and 8 deletions
  1. 1 1
      bbiwarg/Detectors/Palm/PalmDetector.cs
  2. 14 7
      bbiwarg/Utility/Quadrangle.cs

+ 1 - 1
bbiwarg/Detectors/Palm/PalmDetector.cs

@@ -225,7 +225,7 @@ namespace bbiwarg.Detectors.Palm
                     topLeft = bottomLeft + 1.2f * handLength - 0.3f * handWidth;
                 }
 
-                PalmQuad = new Quadrangle(new Vector2D[] { bottomLeft, topLeft, topRight, bottomRight });
+                PalmQuad = new Quadrangle(bottomLeft, topLeft, topRight, bottomRight);
 
                 valid = true;
             }

+ 14 - 7
bbiwarg/Utility/Quadrangle.cs

@@ -10,20 +10,27 @@ namespace bbiwarg.Utility
 {
     class Quadrangle
     {
-        public Vector2D[] Vertices { private set; get; }
+        public Vector2D[] Vertices { get { return new Vector2D[4] {BottomLeft, TopLeft, TopRight, BottomRight}; } }
+        public Vector2D BottomLeft { get; private set; }
+        public Vector2D TopLeft { get; private set; }
+        public Vector2D TopRight { get; private set; }
+        public Vector2D BottomRight { get; private set; }
 
-        public Quadrangle(Vector2D[] vertices)
+        public Quadrangle(Vector2D bottomLeft, Vector2D topLeft, Vector2D topRight, Vector2D bottomRight)
         {
-            Vertices = vertices;
+            BottomLeft = bottomLeft;
+            TopLeft = topLeft;
+            TopRight = topRight;
+            BottomRight = bottomRight;
         }
 
 
         public Vector2D getRelativePosition(Vector2D p)
         {
-            Vector2D a = Vertices[0];
-            Vector2D b = Vertices[1];
-            Vector2D c = Vertices[2];
-            Vector2D d = Vertices[3];
+            Vector2D a = BottomLeft;
+            Vector2D b = TopLeft;
+            Vector2D c = TopRight;
+            Vector2D d = BottomRight;
 
             float C = (a.Y - p.Y) * (d.X - p.X) - (a.X - p.X) * (d.Y - p.Y);
             float B = (a.Y - p.Y) * (c.X - d.X) + (b.Y - a.Y) * (d.X - p.X) - (a.X - p.X) * (c.Y - d.Y) - (b.X - a.X) * (d.Y - p.Y);