//Overloading + operator, it is possible to add two vectors now //for example: C = A + B; public static TwoDimVector operator +(TwoDimVector a, TwoDimVector b) { TwoDimPoint newStart = a.Start; double xLenght = (a.End.X - a.Start.X) + (b.End.X - b.Start.X); double yLenght = (a.End.Y - a.Start.Y) + (b.End.Y - b.Start.Y); TwoDimPoint newEnd = new TwoDimPoint(a.Start.X + xLenght, a.Start.Y + yLenght); return new TwoDimVector(newStart, newEnd); }
public TwoDimVector(TwoDimPoint start, TwoDimPoint end) { CountProperties(start, end); }
public TwoDimVector(string name, TwoDimPoint start, TwoDimPoint end) { Name = name; CountProperties(start, end); }
//helper method to not repeat the code for * operator //vector * number, number * vector and vector / number private static TwoDimPoint[] MultipleVector(double b, TwoDimVector a) { TwoDimPoint[] list = new TwoDimPoint[2]; list[0] = a.Start; double xLenght = (a.End.X - a.Start.X) * b; double yLenght = (a.End.Y - a.Start.Y) * b; list[1] = new TwoDimPoint(a.Start.X + xLenght, a.Start.Y + yLenght); return list; }
public void CountProperties(TwoDimPoint start, TwoDimPoint end) { Start = start; End = end; XLenght = End.X - Start.X >= 0 ? End.X - Start.X : Start.X - End.X; YLenght = End.Y - Start.Y > 0 ? End.Y - Start.Y : Start.Y - End.Y; Lenght = Math.Sqrt(Math.Pow(XLenght, 2) + Math.Pow(YLenght, 2)); }