Procházet zdrojové kódy

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/etri-smartspaces

Daniel Kauth před 10 roky
rodič
revize
522539761b

+ 6 - 7
bbiwarg/Detectors/Fingers/Finger.cs

@@ -4,8 +4,6 @@ using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using Emgu.CV;
-using Emgu.CV.Structure;
 using bbiwarg.Images;
 using bbiwarg.Utility;
 
@@ -16,7 +14,7 @@ namespace bbiwarg.Detectors.Fingers
         private FingerSliceTrail sliceTrail;
         public Vector2D Tip { get { return sliceTrail.Start.Mid; } }
         public Vector2D Hand { get { return sliceTrail.End.Mid; } }
-        public Line2D Line { get { return sliceTrail.Line; } }
+        public LineSegment2D LineSegment { get { return sliceTrail.LineSegment; } }
         public FingerSliceTrail SliceTrail { get { return sliceTrail; } private set { sliceTrail = value; } }
 
         public Finger(FingerSliceTrail sliceTrail)
@@ -26,7 +24,8 @@ namespace bbiwarg.Detectors.Fingers
 
         public float getSimilarity(Finger compareFinger)
         {
-            Line2D compareLine = compareFinger.Line;
+            LineSegment2D compareLineSegment = compareFinger.LineSegment;
+            Line2D compareLine = compareLineSegment.Line;
 
             //thresholds
             float thresholdMaxAngle = (float)(30 * Math.PI / 180); // 30°
@@ -34,15 +33,15 @@ namespace bbiwarg.Detectors.Fingers
             float thresholdMaxVerticalDistance = 40;
 
             //check angle
-            float angle = Line.getAngleBetween(compareLine);
+            float angle = LineSegment.Line.getAngleBetween(compareLine);
             float angleSimilarity = Math.Max(1 - angle / thresholdMaxAngle, 0);
 
             //check parallel distance
-            float parallelDistance = Line.getParallelDistanceTo(compareLine);
+            float parallelDistance = LineSegment.getParallelDistanceTo(compareLineSegment);
             float parallelDistanceSimilarity = Math.Max(1 - parallelDistance / thresholdMaxParallelDistance, 0);
 
             //check vertical distance
-            float verticalDistance = Line.getVerticalDistanceTo(compareLine);
+            float verticalDistance = LineSegment.getVerticalDistanceTo(compareLineSegment);
             float verticalDistanceSimilarity = Math.Max(1 - verticalDistance / thresholdMaxVerticalDistance, 0);
 
             return (angleSimilarity + parallelDistanceSimilarity + verticalDistanceSimilarity) / 3;

+ 5 - 5
bbiwarg/Detectors/Fingers/FingerDetector.cs

@@ -152,8 +152,8 @@ namespace bbiwarg.Detectors.Fingers
                     for (int i = fingers.Count - 1; i >= 0; i--)
                     {
                         Finger f = fingers[i];
-                        Line2D lineA = finger.Line;
-                        Line2D lineB = f.Line;
+                        Utility.LineSegment2D lineA = finger.LineSegment;
+                        Utility.LineSegment2D lineB = f.LineSegment;
 
                         if(lineA.getVerticalDistanceTo(lineB) < 5 && lineA.getParallelDistanceTo(lineB) < 5)
                         {
@@ -178,9 +178,9 @@ namespace bbiwarg.Detectors.Fingers
 
         private bool fingerSliceDepthTest(FingerSlice fingerSlice)
         {
-            Int16 depthStart = depthImage.getDepthAt((int)fingerSlice.Start.X, (int)fingerSlice.Start.Y);
-            Int16 depthMid = depthImage.getDepthAt((int)fingerSlice.Mid.X, (int)fingerSlice.Mid.Y);
-            Int16 depthEnd = depthImage.getDepthAt((int)fingerSlice.End.X, (int)fingerSlice.End.Y);
+            Int16 depthStart = depthImage.getDepthAt(fingerSlice.Start.IntX, fingerSlice.Start.IntY);
+            Int16 depthMid = depthImage.getDepthAt(fingerSlice.Mid.IntX, fingerSlice.Mid.IntY);
+            Int16 depthEnd = depthImage.getDepthAt(fingerSlice.End.IntX, fingerSlice.End.IntY);
             return (depthStart > depthMid && depthMid < depthEnd);
         }
 

+ 1 - 1
bbiwarg/Detectors/Fingers/FingerSlice.cs

@@ -15,7 +15,7 @@ namespace bbiwarg.Detectors.Fingers
         public Vector2D Start { get { return start; } private set { start = value; } }
         public Vector2D Mid { get { return mid; } private set { mid = value; } }
         public Vector2D End { get { return end; } private set { end = value; } }
-        public Line2D Line { get { return new Line2D(Start, End); } }
+        public LineSegment2D Line { get { return new LineSegment2D(Start, End); } }
         public float Size { get { return Start.getDistanceTo(End); } }
 
         public FingerSlice(Vector2D start, Vector2D end) {

+ 1 - 1
bbiwarg/Detectors/Fingers/FingerSliceTrail.cs

@@ -14,7 +14,7 @@ namespace bbiwarg.Detectors.Fingers
         public FingerSlice End { get { return slices[slices.Count - 1]; } }
         public FingerSlice this[int index] { get { return slices[index]; } }
         public int NumSlices { get { return slices.Count; } }
-        public Line2D Line { get { return new Line2D(Start.Mid, End.Mid); } }
+        public LineSegment2D LineSegment { get { return new LineSegment2D(Start.Mid, End.Mid); } }
 
         public FingerSliceTrail(FingerSlice slice)
         {

+ 1 - 1
bbiwarg/Detectors/Fingers/FingerTracker.cs

@@ -63,7 +63,7 @@ namespace bbiwarg.Detectors.Fingers
                 }
                 if (tracked)
                 {
-                    fingerImage.drawLine(finger.Line, FingerImageState.fingerTracked);
+                    fingerImage.drawLine(finger.LineSegment, FingerImageState.fingerTracked);
                     trackedFingers.Add(finger);
                 }
             }

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

@@ -113,9 +113,9 @@ namespace bbiwarg.Detectors.Palm
             foreach (Finger f in fingers)
             {
 
-                if (f.Line.Length > maxLength)
+                if (f.LineSegment.Length > maxLength)
                 {
-                    maxLength = f.Line.Length;
+                    maxLength = f.LineSegment.Length;
                     longest = f;
                 }
             }
@@ -129,7 +129,7 @@ namespace bbiwarg.Detectors.Palm
                 return new Point(0, 0);
             Vector2D direction = (finger.Hand - finger.Tip).normalize();
             Vector2D pos = finger.Hand + 20 * direction;
-            return new Point(HelperFunctions.thresholdRange<int>(0, width - 1, (int)pos.X), HelperFunctions.thresholdRange<int>(0, height - 1, (int)pos.Y));
+            return new Point(HelperFunctions.thresholdRange<int>(0, width - 1, pos.IntX), HelperFunctions.thresholdRange<int>(0, height - 1, pos.IntY));
         }
 
         private void buildPointingHandMask()

+ 2 - 2
bbiwarg/Detectors/Touch/TouchDetector.cs

@@ -34,13 +34,13 @@ namespace bbiwarg.Detectors.Touch
                 if (floodValue > floodValueThreshold)
                 {
                     //correct touchEvent position
-                    Vector2D direction = finger.Line.Direction;
+                    Vector2D direction = finger.LineSegment.Line.Direction;
                     float directionFactor = 10;
                     float x = HelperFunctions.thresholdRange<float>(0, depthImage.getWidth() - 1, tipPoint.X + directionFactor * direction.X);
                     float y = HelperFunctions.thresholdRange<float>(0, depthImage.getHeight() - 1, tipPoint.Y + directionFactor * direction.Y);
                     Vector2D tep = new Vector2D(x,y);
 
-                    touchImage.setTouchAt((int)tep.X, (int)tep.Y, TouchImageState.touchDetected);
+                    touchImage.setTouchAt(tep.IntX, tep.IntY, TouchImageState.touchDetected);
                     TouchEvent touchEvent = new TouchEvent(tep, floodValue, finger);
                     touchEvents.Add(touchEvent);
                 }

+ 1 - 1
bbiwarg/Detectors/Touch/TouchTracker.cs

@@ -49,7 +49,7 @@ namespace bbiwarg.Detectors.Touch
                 }
                 if (tracked)
                 {
-                    touchImage.setTouchAt((int)te.Position.X, (int)te.Position.Y, TouchImageState.touchTracked);
+                    touchImage.setTouchAt(te.Position.IntX, te.Position.IntY, TouchImageState.touchTracked);
                     trackedTouchEvents.Add(te);
                     //Console.WriteLine("touch tracked at x:" + te.getX() + " y:" + te.getY() + " [floodValue:" + te.getFloodValue() + "]");
                 }

+ 2 - 2
bbiwarg/Images/FingerImage.cs

@@ -36,10 +36,10 @@ namespace bbiwarg.Images
             for (int i = 0; i < trail.NumSlices; i++) {
                 drawLine(trail[i].Line, FingerImageState.fingerSlice);
             }
-            drawLine(finger.Line, state);
+            drawLine(finger.LineSegment, state);
         }
 
-        public void drawLine(Line2D line, FingerImageState state)
+        public void drawLine(Utility.LineSegment2D line, FingerImageState state)
         {
             image.Draw(new LineSegment2DF(line.P1, line.P2), new Gray((byte)state), 1);
         }

+ 1 - 1
bbiwarg/MainBBWIWARG.cs

@@ -12,7 +12,7 @@ namespace bbiwarg
     {
         static void Main(string[] args)
         {
-            IInputProvider inputProvider = new IisuInputProvider();//"..\\..\\videos\\touch\\4.skv");
+            IInputProvider inputProvider = new IisuInputProvider("..\\..\\videos\\touch\\4.skv");
             VideoHandle videoHandle = new VideoHandle(inputProvider);
             videoHandle.start();
 

+ 12 - 54
bbiwarg/Utility/Line2D.cs

@@ -15,24 +15,12 @@ namespace bbiwarg.Utility
 
     class Line2D
     {
-        public Vector2D P1 { get; private set; }
-        public Vector2D P2 { get; private set; }
+        public Vector2D PointOnLine { get; private set; }
         public Vector2D Direction { get; private set; }
-        public float Length { get { return P1.getDistanceTo(P2); }}
 
-        public Line2D(Vector2D p1, Vector2D p2)
-        {
-            setPoints(p1, p2);
-        }
-
-        private void setPoints(Vector2D p1, Vector2D p2)
-        {
-            //endpoints
-            P1 = p1;
-            P2 = p2;
-
-            //direction
-            Direction = (P1 - P2).normalize();
+        public Line2D(Vector2D pointOnLine, Vector2D direction) {
+            PointOnLine = pointOnLine;
+            Direction = direction.normalize();
         }
 
         public float getAngleBetween(Line2D line)
@@ -41,37 +29,11 @@ namespace bbiwarg.Utility
             return Math.Min(angle, 180 - angle);
         }
 
-        public float getParallelDistanceTo(Line2D line)
-        {
-            if (onSide(line.P1) != onSide(line.P2)) return 0;
-
-            Vector2D a1 = projectToLine(line.P1);
-            Vector2D a2 = projectToLine(line.P2);
-
-            float distanceA1 = a1.getDistanceTo(line.P1);
-            float distanceA2 = a2.getDistanceTo(line.P2);
-            return Math.Min(distanceA1, distanceA2);
-        }
-
-        public float getVerticalDistanceTo(Line2D line)
-        {
-            Vector2D a1 = projectToLine(line.P1);
-            Vector2D a2 = projectToLine(line.P2);
-
-            if (P1.isInBox(a1, a2) || P2.isInBox(a1, a2)) return 0;
-
-            float distanceP1A1 = P1.getDistanceTo(a1);
-            float distanceP1A2 = P1.getDistanceTo(a2);
-            float distanceP2A1 = P2.getDistanceTo(a1);
-            float distanceP2A2 = P2.getDistanceTo(a2);
-            return Math.Min(Math.Min(distanceP1A1, distanceP1A2), Math.Min(distanceP2A1, distanceP2A2));
-        }
-
         public LineSide onSide(Vector2D point)
         {
             float yPerX = Direction.Y / Direction.X;
-            float xDiff = point.X - P1.X;
-            float newY = P1.Y + yPerX * xDiff;
+            float xDiff = point.X - PointOnLine.X;
+            float newY = PointOnLine.Y + yPerX * xDiff;
             if (newY < point.Y) return LineSide.above;
             else if (newY > point.Y) return LineSide.below;
             else return LineSide.onLine;
@@ -79,7 +41,7 @@ namespace bbiwarg.Utility
 
         public Vector2D projectToLine(Vector2D point)
         {
-            float px = point.X, py = point.Y, dx = Direction.X, dy = Direction.Y, ox = P1.X, oy = P1.Y;
+            float px = point.X, py = point.Y, dx = Direction.X, dy = Direction.Y, ox = PointOnLine.X, oy = PointOnLine.Y;
             float diffx = px - ox;
             float diffy = py - oy;
 
@@ -93,12 +55,12 @@ namespace bbiwarg.Utility
             return new Vector2D(newX, newY);
         }
 
-        public Vector2D intersection(Line2D line)
+        public Vector2D getIntersection(Line2D line)
         {
-            Vector2D p = P1;
-            Vector2D r = P2 - P1;
-            Vector2D q = line.P1;
-            Vector2D s = line.P2 - line.P1;
+            Vector2D p = PointOnLine;
+            Vector2D r = Direction;
+            Vector2D q = line.PointOnLine;
+            Vector2D s = line.Direction;
 
             float r_cross_s = r.cross(s);
             float q_p_cross_s = (q - p).cross(s);
@@ -110,9 +72,5 @@ namespace bbiwarg.Utility
             return p + t * r;
         }
 
-        public override string ToString()
-        {
-            return (int)P1.X + "|" + (int)P1.Y + " --- " + (int)P2.X + "|" + (int)P2.Y;
-        }
     }
 }

+ 63 - 0
bbiwarg/Utility/LineSegment2D.cs

@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bbiwarg.Utility
+{
+
+    class LineSegment2D
+    {
+        public Vector2D P1 { get; private set; }
+        public Vector2D P2 { get; private set; }
+        public Line2D Line { get; private set; }
+        public float Length { get { return P1.getDistanceTo(P2); }}
+
+        public LineSegment2D(Vector2D p1, Vector2D p2)
+        {
+            setPoints(p1, p2);
+        }
+
+        private void setPoints(Vector2D p1, Vector2D p2)
+        {
+            //endpoints
+            P1 = p1;
+            P2 = p2;
+
+            //line
+            Line = new Line2D(P1, P1 - P2);
+        }
+
+        public float getParallelDistanceTo(LineSegment2D line)
+        {
+            if (Line.onSide(line.P1) != Line.onSide(line.P2)) return 0;
+
+            Vector2D a1 = Line.projectToLine(line.P1);
+            Vector2D a2 = Line.projectToLine(line.P2);
+
+            float distanceA1 = a1.getDistanceTo(line.P1);
+            float distanceA2 = a2.getDistanceTo(line.P2);
+            return Math.Min(distanceA1, distanceA2);
+        }
+
+        public float getVerticalDistanceTo(LineSegment2D line)
+        {
+            Vector2D a1 = Line.projectToLine(line.P1);
+            Vector2D a2 = Line.projectToLine(line.P2);
+
+            if (P1.isInBox(a1, a2) || P2.isInBox(a1, a2)) return 0;
+
+            float distanceP1A1 = P1.getDistanceTo(a1);
+            float distanceP1A2 = P1.getDistanceTo(a2);
+            float distanceP2A1 = P2.getDistanceTo(a1);
+            float distanceP2A2 = P2.getDistanceTo(a2);
+            return Math.Min(Math.Min(distanceP1A1, distanceP1A2), Math.Min(distanceP2A1, distanceP2A2));
+        }
+
+        public override string ToString()
+        {
+            return (int)P1.X + "|" + (int)P1.Y + " --- " + (int)P2.X + "|" + (int)P2.Y;
+        }
+    }
+}

+ 0 - 279
bbiwarg/Utility/Vector.cs

@@ -1,279 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace bbiwarg.Utility
-{
-    class Vector<T>
-    {
-        private T[] elements;
-
-        public T x { get { return elements[0]; } set { elements[0] = value; } }
-        public T y { get { return elements[1]; } set { elements[1] = value; } }
-        public T z { get { return elements[2]; } set { elements[2] = value; } }
-
-        public Vector(T x, T y)
-        {
-            elements = new T[2];
-            elements[0] = x;
-            elements[1] = y;
-        }
-
-        public Vector(T x, T y, T z)
-        {
-            elements = new T[3];
-            elements[0] = x;
-            elements[1] = y;
-            elements[2] = z;
-        }
-
-        public Vector(int numberOfElements)
-        {
-            this.elements = new T[numberOfElements];
-        }
-
-        public Vector(T[] elements)
-        {
-            this.elements = elements;
-        }
-
-        public Vector(Vector<T> vector)
-        {
-            this.elements = new T[vector.length()];
-            for (int i = 0; i < elements.Length; i++)
-            {
-                elements[i] = vector[i];
-            }
-        }
-
-        public Vector<T> copy()
-        {
-            Vector<T> newVector = new Vector<T>(this);
-            return newVector;
-        }
-
-        public T this[int index]
-        {
-            get
-            {
-                return elements[index];
-            }
-
-            set
-            {
-                elements[index] = value;
-            }
-        }
-
-        public int length()
-        {
-            return elements.Length;
-        }
-
-        public void add(Vector<T> summand)
-        {
-            for (int i = 0; i < elements.Length; i++)
-            {
-                elements[i] = (dynamic)elements[i] + summand[i];
-            }
-        }
-        public void subtract(Vector<T> subtrahend)
-        {
-            for (int i = 0; i < elements.Length; i++)
-            {
-                elements[i] = (dynamic)elements[i] - subtrahend[i];
-            }
-        }
-
-        public void multiply(T scalar)
-        {
-            for (int i = 0; i < elements.Length; i++)
-            {
-                elements[i] = (dynamic)scalar * elements[i];
-            }
-        }
-
-        public float norm()
-        {
-            return subNorm(elements.Length);
-        }
-
-        public float subNorm(int subLength)
-        {
-            T result = (dynamic)0;
-            for (int i = 0; i < subLength; i++)
-            {
-                result += (dynamic)elements[i] * elements[i];
-            }
-            return (float)Math.Sqrt((dynamic)result);
-        }
-
-        public float distance(Vector<T> vector)
-        {
-            return (vector - this).norm();
-        }
-
-        public float subDistance(Vector<T> vector, int subLength)
-        {
-            return (vector - this).subNorm(subLength);
-        }
-
-        public T sum()
-        {
-            T result = (dynamic)0;
-            for (int i = 0; i < this.length(); i++)
-            {
-                result += (dynamic)elements[i];
-            }
-            return result;
-        }
-
-        public Vector<T> normalize() 
-        {
-            float norm = this.norm();
-            Vector<T> result = new Vector<T>(this);
-            for (int i = 0; i < result.length(); i++)
-            {
-                result[i] = (result[i] / (dynamic)norm);
-            }
-            return result;
-        }
-
-        private static void checkLength(Vector<T> vector1, Vector<T> vector2)
-        {
-            if (vector1.length() != vector2.length())
-                throw new ArgumentException("The vectors must have the same length");
-        }
-
-        public static Vector<T> operator +(Vector<T> summand1, Vector<T> summand2)
-        {
-            checkLength(summand1, summand2);
-
-            Vector<T> result = new Vector<T>(summand1);
-            result.add(summand2);
-            return result;
-        }
-
-        public static Vector<T> operator -(Vector<T> minuend, Vector<T> subtrahend)
-        {
-            checkLength(minuend, subtrahend);
-
-            Vector<T> result = new Vector<T>(minuend);
-            result.subtract(subtrahend);
-            return result;
-        }
-
-        public static T operator *(Vector<T> vector1, Vector<T> vector2)
-        {
-            checkLength(vector1, vector2);
-
-            T result = (dynamic)0;
-            for (int i = 0; i < vector1.length(); i++)
-            {
-                result += (dynamic)vector1[i] * vector2[i];
-            }
-            return result;
-        }
-
-        public static Vector<T> operator *(T factor, Vector<T> vector1)
-        {
-            Vector<T> result = new Vector<T>(vector1);
-            result.multiply(factor);
-            return result;
-        }
-
-        public static bool operator ==(Vector<T> vector1, Vector<T> vector2)
-        {
-            checkLength(vector1, vector2);
-            bool result = true;
-            for (int i = 0; i < vector1.length(); i++)
-            {
-                if (vector1[i] != (dynamic)vector2[i])
-                {
-                    result = false;
-                    break;
-                }
-            }
-            return result;
-        }
-
-        public static bool operator !=(Vector<T> vector1, Vector<T> vector2)
-        {
-            return !(vector1 == vector2);
-        }
-
-        public static Vector<T> crossProduct(Vector<T> vector1, Vector<T> vector2)
-        {
-            if (vector1.length() != 3 || vector2.length() != 3)
-                throw new ArgumentException("The vectors' length should be 3");
-
-            Vector<T> result = new Vector<T>(vector1.length());
-            result[0] = (dynamic)vector1.y * vector2.z - (dynamic)vector1.z * vector2.y;
-            result[1] = (dynamic)vector1.z * vector2.x - (dynamic)vector1.x * vector2.z;
-            result[2] = (dynamic)vector1.x * vector2.y - (dynamic)vector1.y * vector2.x;
-
-            return result;
-        }
-
-        public static Vector<T> pointwiseMultiply(Vector<T> vector1, Vector<T> vector2)
-        {
-            checkLength(vector1, vector2);
-            Vector<T> result = new Vector<T>(vector1);
-            for (int i = 0; i < vector1.length(); i++)
-            {
-                result[i] = (dynamic)result[i] * vector2[i];
-            }
-            return result;
-        }
-
-        public static float distancePointPlane(Vector<T> point, Vector<T> planeA, Vector<T> planeB, Vector<T> planeC)
-        {
-            //TODO - Diese funktion funktioniert nur mit T = float, 
-            //die normalisierte Normale einer Ebene macht nur mit floats sinn (werte zwischen 0 und 1)
-            if (point.length() != 3 || planeA.length() != 3 || planeB.length() != 3 || planeC.length() != 3)
-                throw new ArgumentException("The vectors' length should be 3");
-
-            Vector<T> ab = planeB - planeA;
-            Vector<T> ac = planeC - planeA;
-            Vector<T> normal = crossProduct(ab, ac).normalize();
-            
-
-            Vector<T> temp = point - planeA;
-            temp = pointwiseMultiply(temp, normal);
-            temp = pointwiseMultiply(temp, normal);
-            T sum = temp.sum();
-
-            temp = pointwiseMultiply(normal, normal);
-            T sumR = temp.sum();
-
-            if (sumR == (dynamic)0)
-                throw new ArgumentException("the points do not clamp an Plane");
-
-            float distance = (sum * (dynamic)(-1)) / sumR;
-
-            if (distance < 0)
-                distance *= (float)(-1);
-
-            return distance;
-
-        }
-
-        public static Vector<float> projectToLine(Vector<float> p, Vector<float> direction, Vector<float> pointOnLine)
-        {
-            float px = p.x, py = p.y, dx = direction.x, dy = direction.y, ox = pointOnLine.x, oy = pointOnLine.y;
-            float diffx = px - ox;
-            float diffy = py - oy;
-
-            float diff_d = (diffx * dx + diffy * dy);
-            float d_d = (dx * dx + dy * dy);
-            float q = diff_d / d_d;
-
-            float newX = ox + q * dx;
-            float newY = oy + q * dy;
-
-            return new Vector<float>(newX, newY);
-        }
-    }
-}

+ 38 - 33
bbiwarg/Utility/Vector2D.cs

@@ -9,50 +9,52 @@ namespace bbiwarg.Utility
 {
     class Vector2D
     {
-        private float x;
-        private float y;
-        private float length;
-        public float X { get { return x; } private set { x = value; } }
-        public float Y { get { return y; } private set { y = value; } }
-        public float Length { get { return length; } private set { length = value; } }
+        public float X { get; private set; }
+        public float Y { get; private set; }
+        public int IntX { get { return (int)X; } }
+        public int IntY { get { return (int)Y; } }
+        public float Length { get { return (float)Math.Sqrt(X * X + Y * Y); } }
 
-        public Vector2D(float x, float y) {
-            setXY(x, y);
+        public Vector2D(float x, float y)
+        {
+            X = x;
+            Y = y;
         }
 
-        public Vector2D(Point point) {
-            setXY(point.X, point.Y);
+        public Vector2D(Point point)
+        {
+            X = point.X;
+            Y = point.Y;
         }
 
         public Vector2D(PointF point)
         {
-            setXY(point.X, point.Y);
+            X = point.X;
+            Y = point.Y;
         }
 
-        public static implicit operator PointF(Vector2D vec)
+        public float getDistanceTo(Vector2D point)
         {
-            return new PointF(vec.X, vec.Y);
-        }
-
-        private void setXY(float x, float y) {
-            X = x;
-            Y = y;
-            Length = (float)Math.Sqrt(X * X + Y * Y);
-        }
-
-        public float getDistanceTo(Vector2D point) {
             return (this - point).Length;
         }
 
-        public float getAngleBetween(Vector2D vector) {
+        public float getAngleBetween(Vector2D vector)
+        {
             return (float)Math.Acos(dotProduct(vector) / (Length * vector.Length));
         }
 
-        public float dotProduct(Vector2D vector) {
+        public float dotProduct(Vector2D vector)
+        {
             return X * vector.X + Y * vector.Y;
         }
 
-        public bool isInBox(Vector2D corner1, Vector2D corner2) {
+        public float cross(Vector2D v)
+        {
+            return X * v.Y - Y * v.X;
+        }
+
+        public bool isInBox(Vector2D corner1, Vector2D corner2)
+        {
             float minX = Math.Min(corner1.X, corner2.X);
             float maxX = Math.Max(corner1.X, corner2.X);
             float minY = Math.Min(corner1.Y, corner2.Y);
@@ -60,7 +62,8 @@ namespace bbiwarg.Utility
             return (minX <= X && X <= maxX && minY <= Y && Y <= maxY);
         }
 
-        public Vector2D normalize() {
+        public Vector2D normalize()
+        {
             return new Vector2D(X / Length, Y / Length);
         }
 
@@ -94,18 +97,20 @@ namespace bbiwarg.Utility
             return new Vector2D(vector1.X - vector2.X, vector1.Y - vector2.Y);
         }
 
-        public float cross(Vector2D v)
+        public static Vector2D mean(List<Vector2D> vectors)
         {
-            return X * v.Y - Y * v.X;
-        }
-
-        public static Vector2D mean(List<Vector2D> vectors) {
-            Vector2D meanVector = new Vector2D(0,0);
-            foreach (Vector2D vector in vectors) {
+            Vector2D meanVector = new Vector2D(0, 0);
+            foreach (Vector2D vector in vectors)
+            {
                 meanVector += vector;
             }
             return meanVector / vectors.Count;
         }
 
+        public static implicit operator PointF(Vector2D vec)
+        {
+            return new PointF(vec.X, vec.Y);
+        }
+
     }
 }

+ 1 - 1
bbiwarg/bbiwarg.csproj

@@ -91,8 +91,8 @@
     <Compile Include="Utility\HelperFunctions.cs" />
     <Compile Include="Utility\KalmanFilter.cs" />
     <Compile Include="Utility\Line2D.cs" />
+    <Compile Include="Utility\LineSegment2D.cs" />
     <Compile Include="Utility\Quadrangle.cs" />
-    <Compile Include="Utility\Vector.cs" />
     <Compile Include="Utility\Vector2D.cs" />
     <Compile Include="VideoHandle.cs" />
   </ItemGroup>