-
Notifications
You must be signed in to change notification settings - Fork 0
/
LineSegment.cs
55 lines (47 loc) · 1.56 KB
/
LineSegment.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
using System;
using System.Collections.Generic;
namespace WSMath.Delaunay
{
public class LineSegment
{
public static List<LineSegment> VisibleLineSegments(List<Edge> edges)
{
List<LineSegment> segments = new List<LineSegment>();
foreach (Edge edge in edges)
{
if (edge.Visible())
{
Vector2f p1 = edge.ClippedEnds[LR.LEFT];
Vector2f p2 = edge.ClippedEnds[LR.RIGHT];
segments.Add(new LineSegment(p1, p2));
}
}
return segments;
}
public static float CompareLengths_MAX(LineSegment segment0, LineSegment segment1)
{
float length0 = segment0.p0.HasValue ? (segment0.p0.Value - segment0.p1.Value).magnitude : 0f;
float length1 = segment0.p0.HasValue ? (segment1.p0.Value - segment1.p1.Value).magnitude : 0f;
if (length0 < length1)
{
return 1;
}
if (length0 > length1)
{
return -1;
}
return 0;
}
public static float CompareLengths(LineSegment edge0, LineSegment edge1)
{
return -CompareLengths_MAX(edge0, edge1);
}
public Nullable<Vector2f> p0;
public Nullable<Vector2f> p1;
public LineSegment(Nullable<Vector2f> p0, Nullable<Vector2f> p1)
{
this.p0 = p0;
this.p1 = p1;
}
}
}