public Rectangle(Point first, Point second) { if (first.GetX == second.GetX || first.GetY == second.GetY) { throw new ArgumentException("Points cannot be on same axis!"); } if (first.GetY > second.GetY) { //Reverse points to avoid exceptions Point tempPoint = first; first = second; second = tempPoint; } this.width = second.GetX - first.GetX; this.height = second.GetY - first.GetY; this.lowerLeftPoint = first; this.upperLeftPoint = new Point(first.GetX, second.GetY - this.width); this.upperRightPoint = second; this.lowerRightPoint = new Point(second.GetX, first.GetY + this.width); this.upperSide = new LineSegment(this.upperLeftPoint, this.upperRightPoint); this.lowerSide = new LineSegment(this.lowerLeftPoint, this.lowerRightPoint); this.leftSide = new LineSegment(this.lowerLeftPoint, this.upperLeftPoint); this.rightSide = new LineSegment(this.lowerRightPoint, this.upperRightPoint); this.center = new Point(first.GetX + this.width / 2, first.GetY + this.height / 2); }
public Rectangle(Rectangle rectangle) { Point first = rectangle.lowerLeftPoint; Point second = rectangle.upperRightPoint; if (first.GetY > second.GetY) { //Reverse points to avoid exceptions Point tempPoint = first; first = second; second = tempPoint; } this.width = second.GetX - first.GetX; this.height = second.GetY - first.GetY; this.lowerLeftPoint = first; this.upperLeftPoint = new Point(first.GetX, second.GetY - this.width); this.upperRightPoint = second; this.lowerRightPoint = new Point(second.GetX, first.GetY + this.width); this.upperSide = new LineSegment(this.upperLeftPoint, this.upperRightPoint); this.lowerSide = new LineSegment(this.lowerLeftPoint, this.lowerRightPoint); this.leftSide = new LineSegment(this.lowerLeftPoint, this.upperLeftPoint); this.rightSide = new LineSegment(this.lowerRightPoint, this.upperRightPoint); this.center = new Point(first.GetX + this.width / 2, first.GetY + this.height / 2); }
public Rectangle(Point firstPoint, Point secondPoint) { PointA = new Point(Math.Min(firstPoint.x, secondPoint.x), Math.Min(firstPoint.y, secondPoint.y)); PointB = new Point(Math.Max(firstPoint.x, secondPoint.x), Math.Min(firstPoint.y, secondPoint.y)); PointC = new Point(Math.Max(firstPoint.x, secondPoint.x), Math.Max(firstPoint.y, secondPoint.y)); PointD = new Point(Math.Min(firstPoint.x, secondPoint.x), Math.Max(firstPoint.y, secondPoint.y)); AB = new LineSegment(A, B); CD = new LineSegment(C, D); }
public Rectangle(Point p1, Point p2) { PointA = new Point(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y)); PointB = new Point(Math.Max(p1.X, p2.X), Math.Min(p1.Y, p2.Y)); PointC = new Point(Math.Max(p1.X, p2.X), Math.Max(p1.Y, p2.Y)); PointD = new Point(Math.Min(p1.X, p2.X), Math.Max(p1.Y, p2.Y)); AB = new LineSegment(A,B); BC = new LineSegment(B, C); }
/// <summary> /// Initializes a new instance of the <see cref="Rectangle"/> class. /// </summary> /// <param name="p1">Point one.</param> /// <param name="p2">Point two.</param> public Rectangle(Point p1, Point p2) { this.PointA = new Point(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y)); this.PointC = new Point(Math.Max(p1.X, p2.X), Math.Max(p1.Y, p2.Y)); this.PointB = new Point(Math.Max(p1.X, p2.X), Math.Min(p1.Y, p2.Y)); this.PointD = new Point(Math.Min(p1.X, p2.X), Math.Max(p1.Y, p2.Y)); this.ab = new LineSegment(this.PointA, this.PointB); this.bc = new LineSegment(this.PointB, this.PointC); }
public Rectangle(Rectangle rect) { lowerLeftPoint = new Point(rect.lowerLeftPoint.X, rect.lowerLeftPoint.Y); lowerRightPoint = new Point(rect.lowerRightPoint.X, rect.lowerRightPoint.Y); upperLeftPoint = new Point(rect.upperLeftPoint.X, rect.upperLeftPoint.Y); upperRightPoint = new Point(rect.upperRightPoint.X, rect.upperRightPoint.Y); lowerSide = new LineSegment(rect.lowerSide.StartPoint, rect.lowerSide.EndPoint); upperSide = new LineSegment(rect.upperSide.StartPoint, rect.upperSide.EndPoint); leftSide = new LineSegment(rect.leftSide.StartPoint, rect.leftSide.EndPoint); rightSide = new LineSegment(rect.rightSide.StartPoint, rect.rightSide.EndPoint); width = rect.width; height = rect.height; center = new Point(rect.center.X, rect.center.Y); }
static void Main(string[] args) { Point p1 = new Point(1.2, 2.1); Point p2 = new Point(5.4, 7.2); Console.WriteLine("{0} + {1} = {2}", p1, p2, p1 + p2); Console.WriteLine(); LineSegment ls1 = new LineSegment(new Point(1, 1), new Point(1, 5)); LineSegment ls2 = new LineSegment(new Point(2, 3), new Point(4, 5)); Console.WriteLine("{0} -> Length: {1}", ls1, ls1.GetLength()); Console.WriteLine("{0} -> Length: {1}", ls2, ls2.GetLength()); Console.WriteLine(); Rectangle rect = new Rectangle(p1, p2); Rectangle rect2 = new Rectangle(p2, p1); Console.WriteLine("Is {0} equal to {1} -> {2}", rect, rect2, rect.Equals(rect2)); Console.WriteLine(); Console.WriteLine("Rectangle from {0} and {1} has these properties:", p1, p2); Console.WriteLine("Width: {0}", rect.Width); Console.WriteLine("Height: {0}", rect.Height); Console.WriteLine("Lower Left: {0}", rect.LowerLeftPoint); Console.WriteLine("Lower Rigth: {0}", rect.LowerRightPoint); Console.WriteLine("Upper Left: {0}", rect.UpperLeftPoint); Console.WriteLine("Upper Rigth: {0}", rect.UpperRightPoint); Console.WriteLine("Perimeter: {0}", rect.GetPerimeter()); Console.WriteLine("Area: {0}", rect.GetArea()); Console.WriteLine("Center: {0}", rect.Center); Console.WriteLine(); Vector v1 = new Vector(1, 2, 3, 4); Vector v2 = new Vector(7, 3, 8, 1); Console.WriteLine("{0} + {1} = {2}", v1, v2, v1 + v2); Console.WriteLine("{0} - {1} = {2}", v1, v2, v1 - v2); Console.WriteLine("{0} * {1} = {2}", v1, v2, v1 * v2); Console.WriteLine("{0} - {1} = {2}", v1, 0.2, v1 - 0.2); Console.WriteLine("{0} * {1} = {2}", v1, 0.2, v1 * 0.2); Console.ReadKey(); }
/// <summary> /// Main Method. /// </summary> public static void Main() { Point point = new Point(0, 0); Point point2 = new Point(4, 4); Point point3 = new Point(5, 5); Point point4 = new Point(1, 1); LineSegment line = new LineSegment(point, point2); LineSegment line2 = new LineSegment(point3, point4); Rectangle rect = new Rectangle(point, point2); Rectangle rect2 = new Rectangle(point3, point4); // TODO : properties for edges; Vector vect1 = new Vector(1, 2, 3); Vector vect2 = new Vector(4, 5, 6); Console.WriteLine(vect1 * vect2); }
static void Main(string[] args) { Point firstPoint = new Point(5, 5); Point secondPoint = new Point(7, 7); LineSegment first = new LineSegment(firstPoint, secondPoint); LineSegment second = new LineSegment(firstPoint, secondPoint); Console.WriteLine(first > second); Console.WriteLine(first >= second); Console.WriteLine(first == second); LineSegment twoPoints = firstPoint + secondPoint; Rectangle rect = new Rectangle(firstPoint, secondPoint); Rectangle anotherRect = new Rectangle(secondPoint, firstPoint); Console.WriteLine("Equals: " + rect.Equals(anotherRect)); Console.WriteLine(); Console.WriteLine("Width: {0}", rect.GetWidth); Console.WriteLine("Height: {0}", rect.GetHeight); Console.WriteLine("Lower Left: {0}", rect.GetLowerLeftPoint); Console.WriteLine("Lower Rigth: {0}", rect.GetLowerRightPoint); Console.WriteLine("Upper Left: {0}", rect.GetUpperLeftPoint); Console.WriteLine("Upper Rigth: {0}", rect.GetUpperRightPoint); Console.WriteLine("Perimeter: {0}", rect.GetPerimeter()); Console.WriteLine("Area: {0}", rect.GetArea()); Console.WriteLine("Center: {0}", rect.GetCenterPoint); Console.WriteLine(); Vector vector = new Vector(new double[] { 1, 2, 3, 4 }); Vector anotherVector = new Vector(new double[] { 5, 6, 7, 8, 9 }); Console.WriteLine("{0} + {1} = {2}", vector, anotherVector, vector + anotherVector); Console.WriteLine("{0} - {1} = {2}", vector, anotherVector, vector - anotherVector); Console.WriteLine("{0} * {1} = {2}", vector, anotherVector, vector * anotherVector); double scalar = 0.7; Console.WriteLine("{0} - {1} = {2}", vector, scalar, vector - scalar); Console.WriteLine("{0} * {1} = {2}", vector, scalar, vector * scalar); Console.WriteLine(); }
public Rectangle(Point p1, Point p2) { if (p1.X == p2.X || p1.Y == p2.Y) throw new ArgumentException("Points on same axis, can't create rectangle"); if (p1.Y > p2.Y) { Point temp = p1; p1 = p2; p2 = temp; } width = p2.X - p1.X; height = p2.Y - p1.Y; lowerLeftPoint = p1; upperLeftPoint = new Point(p1.X, p2.Y - width); upperRightPoint = p2; lowerRightPoint = new Point(p2.X, p1.Y + width); lowerSide = new LineSegment(lowerLeftPoint, lowerRightPoint); upperSide = new LineSegment(upperLeftPoint, upperRightPoint); leftSide = new LineSegment(lowerLeftPoint, upperLeftPoint); rightSide = new LineSegment(lowerRightPoint, upperRightPoint); center = new Point(p1.X + width / 2, p1.Y + height / 2); }
LineSegment(LineSegment other) { this.startPoint = other.startPoint; this.endPoint = other.endPoint; }
public static LineSegment operator +(Point a, Point b) { LineSegment newLine = new LineSegment(a, b); return newLine; }
public LineSegment(LineSegment ls) { firstPoint = new Point(ls.firstPoint.X, ls.firstPoint.Y); secondPoint = new Point(ls.secondPoint.X, ls.secondPoint.Y); }
public LineSegment(LineSegment ab) { a = ab.a; b = ab.b; }
public LineSegment(LineSegment lineSigment) { this.firstPoint = lineSigment.firstPoint; this.secondPoint = lineSigment.secondPoint; }
public LineSegment(LineSegment line) { start = line.Start; end = line.End; }