Ejemplo n.º 1
0
        static ImmutableArray <Point> getSegmentRatios(GetSegmentLength getSegmentLength, ImmutableArray <Vector3> nodes)
        {
            var builder = ImmutableArray.CreateBuilder <Point>(nodes.Length);

            var length       = 0f;
            var lengthsCount = nodes.Length - 1;
            var lengths      = new float[lengthsCount];

            for (var idx = 0; idx < lengthsCount; idx++)
            {
                var segLength = getSegmentLength(idx);
                length      += segLength;
                lengths[idx] = segLength;
            }

            // Creating points
            builder.Add(new Point(nodes[0], 0f, 0f));
            for (var idx = 1; idx < nodes.Length; idx++)
            {
                var previousNodeLength = lengths[idx - 1];
                var previousPoint      = builder[idx - 1];
                builder.Add(new Point(
                                point: nodes[idx],
                                percentageOfPathTraveled: previousNodeLength / length + previousPoint.percentageOfPathTraveled,
                                realDistanceToThisPoint: previousNodeLength + previousPoint.realDistanceToThisPoint
                                ));
            }

            return(builder.MoveToImmutable());
        }
Ejemplo n.º 2
0
        private void CreateCanvasGeometry(CanvasVirtualControl device)
        {
            switch (GeometryType)
            {
            case GeometryType.Rectangle:
                _geometry = CanvasGeometry.CreateRectangle(device, (float)Points[0].X, (float)Points[0].Y,
                                                           (float)Points[1].X - (float)Points[0].X, (float)Points[1].Y - (float)Points[0].Y);
                break;

            case GeometryType.Line:
                _geometry = CanvasGeometry.CreatePolygon(device,
                                                         new Vector2[]
                {
                    new Vector2((float)Points[0].X, (float)Points[0].Y),
                    new Vector2((float)Points[1].X, (float)Points[1].Y)
                });
                break;

            case GeometryType.Circle:
                _geometry = CanvasGeometry.CreateCircle(device, new Vector2((float)Points[0].X, (float)Points[0].Y), GetSegmentLength.CalculateSegmentLength(Points[0], Points[1]));
                break;
            }
        }
Ejemplo n.º 3
0
        private CanvasGeometry CreateCanvasGeometry(CanvasVirtualControl device)
        {
            switch (GeometryType)
            {
            case GeometryType.Rectangle:
                return(CanvasGeometry.CreateRectangle(device, (float)Points[0].X, (float)Points[0].Y,
                                                      (float)MapController.Instance.MousePosition.X - (float)Points[0].X, (float)MapController.Instance.MousePosition.Y - (float)Points[0].Y));

            case GeometryType.Line:
                CanvasPathBuilder pathBuilder = new CanvasPathBuilder(device);
                pathBuilder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin);
                pathBuilder.BeginFigure((float)Points[0].X, (float)Points[0].Y);
                pathBuilder.AddLine(new Vector2((float)MapController.Instance.MousePosition.X, (float)MapController.Instance.MousePosition.Y));
                pathBuilder.EndFigure(CanvasFigureLoop.Open);
                return(CanvasGeometry.CreatePath(pathBuilder));

            case GeometryType.Circle:
                return(CanvasGeometry.CreateCircle(device, new Vector2((float)Points[0].X, (float)Points[0].Y), GetSegmentLength.CalculateSegmentLength(Points[0], MapController.Instance.MousePosition)));
            }
            return(null);
        }