static void Main(string[] args) { Figure fgr1 = new Figure("Square"); Point pnt1 = new Point(1, 2, 3, "A"); Point pnt2 = new Point(2, 5, 10, "B"); Point pnt3 = new Point(4, 2, 7, "C"); Point pnt4 = new Point(1, 2, 3, "D"); fgr1.Insert(pnt1); fgr1.Insert(pnt2); fgr1.Insert(pnt3); fgr1.Insert(pnt4); fgr1.PrintFigure(); Console.WriteLine("Total figures: {0}", Figure.GetNumberOfFigures()); Console.WriteLine("Total number of point in figure: {0}", fgr1.GetNumberOfPoints()); Console.WriteLine("Is point A the same with point D? {0}", pnt1.Equals(pnt4)); Console.WriteLine("Hash code of current figure (overriden): {0}", fgr1.GetHashCode()); // --------------------------------------------------------------------------------------- Console.WriteLine("*******************"); // --------------------------------------------------------------------------------------- Console.WriteLine("Current size of figure 1: {0:F3}", SMathFigure.GetFigureSize(fgr1)); // --------------------------------------------------------------------------------------- Console.WriteLine("*******************"); var figure = new {Name = "Triangle", Point1 = pnt1.GetName(), Point2 = pnt2.GetName(), Point3 = pnt3.GetName()}; Console.WriteLine("Anonymous type by template: Name {0}, Point 1 name {1}, Point 2 name {2}, Point 3 name {3}", figure.Name, figure.Point1, figure.Point2, figure.Point3); // --------------------------------------------------------------------------------------- Console.WriteLine("*******************"); Figure fgr2 = new Figure("Sphere"); Point pnt1_1 = new Point(1, 1, 1, "A"); Point pnt1_2 = new Point(2, 2, 2, "B"); Point pnt1_3 = new Point(3, 3, 3, "C"); Point pnt1_4 = new Point(4, 4, 4, "D"); fgr2.Insert(pnt1_1); fgr2.Insert(pnt1_2); fgr2.Insert(pnt1_3); fgr2.Insert(pnt1_4); double sizeOfFigure1 = 0; double sizeOfFigure2 = 0; Console.WriteLine("Extended method: {0}", fgr1.GetVectorSize()); bool flag = SMathFigure.IsCanBePlacedInside(ref fgr1, ref fgr2, out sizeOfFigure1, out sizeOfFigure2); Console.WriteLine("Is {0} with size of {1:F2} can be placed inside of {2} with size of {3:F2}? {4}", fgr1.GetNameOfFigure(), sizeOfFigure1, fgr2.GetNameOfFigure(), sizeOfFigure2, flag); Console.ReadKey(); }
public static double GetFigureSize(Figure _fgr) { double size = 0; double allX = 0; double allY = 0; double allZ = 0; foreach (Point pnt in _fgr.GetArray()) { allX += pnt.GetX(); allY += pnt.GetY(); allZ += pnt.GetZ(); } size = Math.Sqrt(Math.Pow(allX, 2) + Math.Pow(allY, 2) + Math.Pow(allZ, 2)); return size; }
public static bool IsCanBePlacedInside(ref Figure RFgr1, ref Figure RFgr2, out double OSize1, out double OSize2) { OSize1 = GetFigureSize(RFgr1); OSize2 = GetFigureSize(RFgr2); return OSize1 >= OSize2 ? false : true; }