示例#1
0
 public override void validate()
 {
     if (2 * Sides.Max() >= Sides.Sum())
     {
         throw new ArgumentException("Not a figure");
     }
 }
示例#2
0
        /// <summary>
        /// initialize a square through one or three sides and other skin figure.
        /// </summary>
        /// <param name="sidesCollection">Three sides</param>
        /// <param name="figure">Other skin figure</param>
        public TrianglePellicle(IEnumerable <double> sidesCollection, IPellicleFigure figure) : base(sidesCollection)
        {
            double area = Math.Sqrt((Sides.Sum() / 2) * ((Sides.Sum() / 2) - Sides[0]) * ((Sides.Sum() / 2) - Sides[1]) * ((Sides.Sum() / 2) - Sides[2]));

            if (area > figure.GetArea())
            {
                throw new ArgumentException();
            }
        }
        /// <summary>
        /// Constructor to initialize a square through one or three sides and other skin figure.
        /// </summary>
        /// <param name="sidesCollection">Three sides</param>
        /// <param name="figure">Other skin figure</param>
        public SkinTriangle(IEnumerable <double> sidesCollection, ISkinFigure figure) : base(sidesCollection)
        {
            double halfPerimetr = Sides.Sum() / 2;
            double area         = Math.Sqrt(halfPerimetr * (halfPerimetr - Sides[0]) * (halfPerimetr - Sides[1]) * (halfPerimetr - Sides[2]));

            if (area > figure.GetArea())
            {
                throw new ArgumentException("You cannot create a shape because the original shape is smaller.");
            }
        }
示例#4
0
        public override double area()
        {
            validate();
            if (2 * Sides.Max() >= Sides.Sum())
            {
                throw new ArgumentException("Not a figure");
            }
            if (Math.Pow(Sides.Max(), 2) * 2 == Math.Pow(Sides[0], 2) + Math.Pow(Sides[1], 2) + Math.Pow(Sides[2], 2))
            {
                return(Sides[0] * Sides[1] * Sides[2] / Sides.Max() / 2);
            }
            double hper = Sides.Sum() / 2;

            return(Math.Sqrt(hper * (hper - Sides[0]) * (hper - Sides[1]) * (hper - Sides[2])));
        }
示例#5
0
 public override double FindPerimeter()
 {
     return(Sides.Sum());
 }
示例#6
0
        public override double CalculateArea()
        {
            double p = Sides.Sum() / 2;

            return(Math.Sqrt(p * (p - Sides[0]) * (p - Sides[1]) * (p - Sides[2])));
        }
示例#7
0
 public override double CalculatePerimeter()
 {
     return(Sides.Sum());
 }