/
PolylineGeometry.cs
79 lines (71 loc) · 2.24 KB
/
PolylineGeometry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using Perspex.Platform;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex.Media
{
/// <summary>
/// Represents the geometry of an polyline or polygon.
/// </summary>
public class PolylineGeometry : Geometry
{
private IList<Point> _points;
private bool _isFilled;
public PolylineGeometry(IList<Point> points, bool isFilled)
{
_points = points;
_isFilled = isFilled;
IPlatformRenderInterface factory = PerspexLocator.Current.GetService<IPlatformRenderInterface>();
IStreamGeometryImpl impl = factory.CreateStreamGeometry();
using (IStreamGeometryContextImpl context = impl.Open())
{
if (points.Count > 0)
{
context.BeginFigure(points[0], isFilled);
for (int i = 1; i < points.Count; i++)
{
context.LineTo(points[i]);
}
context.EndFigure(isFilled);
}
}
PlatformImpl = impl;
}
/// <inheritdoc/>
public override Rect Bounds
{
get
{
double xMin = double.MaxValue, yMin = double.MaxValue;
double xMax = double.MinValue, yMax = double.MinValue;
foreach (var point in _points)
{
if (point.X < xMin)
{
xMin = point.X;
}
else if (point.X > xMax)
{
xMax = point.X;
}
if (point.Y < yMin)
{
yMin = point.Y;
}
else if (point.Y > yMax)
{
yMax = point.Y;
}
}
return new Rect(xMin, yMin, xMax - xMin, yMax - yMin);
}
}
/// <inheritdoc/>
public override Geometry Clone()
{
return new PolylineGeometry(new List<Point>(_points), _isFilled);
}
}
}