private static double CalcFigureContour(FigureContour fContour)
        {
            var points = new List <Point>();

            foreach (var p in fContour.Objects)
            {
                if (points.LastOrDefault()?.Equals(p.Begin) ?? true)
                {
                    points.Add(p.Begin);
                }
                points.Add(p.End);

                if (p is ContourArc arc)
                {
                    var area = (arc.Radius * arc.Radius) * 0.5 *
                               (Math.PI * arc.Angle / 180 - Math.Sin(arc.Angle * Math.PI / 180));
                }
            }


            return(CalcPoints(points));
        }
        public void ParseArcOrLine()
        {
            _contour = new FigureContour {
                Orientation = !_partProfile.Contours.Any() ? "Positive" : "Negative"
            };
            _lastPoint = null;
            while (_linesLeftToParse > 0)
            {
                _point = ParsePoint(GetValue(StreamReader.ReadLine()));
                _linesLeftToParse--;

                if (_point.B > 0 || _point.B < 0)
                {
                    ParseArc();
                }
                else
                {
                    ParseLine();
                }
                _lastPoint = _point;
            }
            _contour.CloseContour();
            _partProfile.Contours.Add(_contour);
        }
Пример #3
0
        public void CalcSquareArea()
        {
            var outerContour = new FigureContour
            {
                Objects = new List <ContourObject>
                {
                    new ContourLine {
                        Begin = new Point {
                            X = 0, Y = 0
                        }, End = new Point {
                            X = 0, Y = 1000
                        }
                    },
                    new ContourLine {
                        Begin = new Point {
                            X = 0, Y = 1000
                        }, End = new Point {
                            X = 1000, Y = 1000
                        }
                    },
                    new ContourLine {
                        Begin = new Point {
                            X = 1000, Y = 1000
                        }, End = new Point {
                            X = 1000, Y = 0
                        }
                    },
                    new ContourLine {
                        Begin = new Point {
                            X = 1000, Y = 0
                        }, End = new Point {
                            X = 0, Y = 0
                        }
                    }
                }
            };

            var innerContour = new FigureContour
            {
                Objects = new List <ContourObject>
                {
                    new ContourLine {
                        Begin = new Point {
                            X = 10, Y = 10
                        }, End = new Point {
                            X = 10, Y = 110
                        }
                    },
                    new ContourLine {
                        Begin = new Point {
                            X = 10, Y = 110
                        }, End = new Point {
                            X = 110, Y = 110
                        }
                    },
                    new ContourLine {
                        Begin = new Point {
                            X = 110, Y = 110
                        }, End = new Point {
                            X = 110, Y = 10
                        }
                    },
                    new ContourLine {
                        Begin = new Point {
                            X = 110, Y = 10
                        }, End = new Point {
                            X = 10, Y = 10
                        }
                    }
                }
            };

            var partProfile = new PartProfile
            {
                Contours = new List <Contour> {
                    outerContour, innerContour
                }
            };

            Assert.AreEqual(1000000 - 10000, CalcHelper.CalcArea(partProfile));
        }