Esempio n. 1
0
        public MarkGeometrySpline(Spline spline)
            : base()
        {
            FitPoints     = spline.FitPoints.ConvertAll(x => new MarkGeometryPoint(x));
            ControlPoints = new List <SplineVertex>(spline.ControlPoints).ConvertAll(x => new MarkGeometryPoint(x.Position));;
            Knots         = spline.Knots.ToList();
            IsPeriodic    = spline.IsPeriodic;
            IsClosed      = spline.IsClosed;
            Degree        = spline.Degree;

            // TODO : Remove
            var polyline = spline.ToPolyline(spline.ControlPoints.Count * 5);

            Points.AddRange(
                polyline.Vertexes.Select(v => new MarkGeometryPoint(v.Position))
                );

            if (
                polyline.IsClosed &&
                GeometricArithmeticModule.Compare(StartPoint, EndPoint, ClosureTolerance) != 0)
            {
                Points.Add((MarkGeometryPoint)StartPoint.Clone());
            }
            // END Remove

            Update();
        }
Esempio n. 2
0
        /// <summary>
        /// Add point to the end of the path
        /// </summary>
        /// <param name="point"></param>
        /// <param name="deferUpdate"></param>
        public void Append(MarkGeometryPoint point, bool deferUpdate = false)
        {
            if (
                Points.Count > 0 &&
                GeometricArithmeticModule.Compare(EndPoint, point, ClosureTolerance) == 0
                )
            {
                return; // ignore existing points
            }
            Points.Add(point);

            if (!deferUpdate)
            {
                Update();
            }
        }
Esempio n. 3
0
        public void Merge(MarkGeometryPath path)
        {
            if (
                GeometricArithmeticModule.Compare(EndPoint, path.StartPoint, ClosureTolerance) == 0
                )
            {
                // skip the path's start point if its the
                // same as this path's end point
                Points.AddRange(path.Points.Skip(1));
            }
            else
            {
                Points.AddRange(path.Points);
            }


            Update();
        }
Esempio n. 4
0
        //public MarkGeometryPath(LwPolyline lwPolyline)
        //    : base()
        //{
        //    foreach (var entity in lwPolyline.Explode())
        //    {
        //        if (entity is Line lineEntity)
        //        {
        //            Points.Add(new MarkGeometryPoint(lineEntity.StartPoint));
        //            Points.Add(new MarkGeometryPoint(lineEntity.EndPoint));
        //        }
        //        else if (entity is Arc arcEntity)
        //        {
        //            arcEntity.PolygonalVertexes
        //        }
        //    }
        //    Points.AddRange(
        //        lwPolyline.Vertexes.ConvertAll(v => new MarkGeometryPoint(v))
        //    );

        //    if (
        //        lwPolyline.IsClosed &&
        //        GeometricArithmeticModule.Compare(StartPoint, EndPoint, ClosureTolerance) != 0)
        //    {
        //        Points.Add((MarkGeometryPoint)StartPoint.Clone());
        //    }

        //    // TODO : Calculate centroid
        //    CentrePoint = new MarkGeometryPoint();
        //    Update();
        //}

        public MarkGeometryPath(Polyline polyline)
            : base()
        {
            Points.AddRange(
                polyline.Vertexes.Select(v => new MarkGeometryPoint(v.Position))
                );

            if (
                polyline.IsClosed &&
                GeometricArithmeticModule.Compare(StartPoint, EndPoint, ClosureTolerance) != 0)
            {
                Points.Add((MarkGeometryPoint)StartPoint.Clone());
            }

            // TODO : Calculate centroid
            CentrePoint = new MarkGeometryPoint();
            Update();
        }
Esempio n. 5
0
        public override void Update()
        {
            // you need at least four points to
            // make a filled path
            IsClosed = (Points.Count >= 4) &&
                       GeometricArithmeticModule.Compare(
                StartPoint,
                EndPoint,
                ClosureTolerance
                ) == 0;

            // Perimeter is calculated within SetExtents
            SetExtents();

            if (Points.Count < 2)
            {
                Area = 0; // same as point
                return;
            }
            else if (Points.Count < 4)
            {
                Area = Extents.Hypotenuse * Double.Epsilon; // same as line
                return;
            }

            // calculating area of an irregular polygon
            double A = 0;
            double B = 0;

            for (var i = 0; i < Points.Count - 1; i++)
            {
                A += Points[i].X * Points[i + 1].Y;
                B += Points[i].Y * Points[i + 1].X;
            }

            if (!IsClosed)
            {
                A += EndPoint.X * StartPoint.Y;
                B += EndPoint.Y * StartPoint.X;
            }

            Area = Math.Abs((A - B) / 2.0);
        }