-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHull.cs
107 lines (94 loc) · 2.14 KB
/
Hull.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace _1_convex_hull {
public class Hull {
List<PointF> points;
PointF rightMostPoint;
Dictionary<PointF, int> pointIndexDict;
public PointF getNext(PointF point){
int currentIndex = pointIndexDict[point];
int newIndex = (currentIndex + 1) % points.Count;
return points[newIndex];
}
public int getNextIndex(int currentIndex){
if(currentIndex == this.points.Count - 1){
return 0;
}
else {
return currentIndex + 1;
}
}
public PointF getPrev(PointF point){
try {
int currentIndex = pointIndexDict[point];
int newIndex = (currentIndex - 1) % points.Count;
if (newIndex < 0) {
newIndex = ~newIndex + 1;
}
return points[newIndex];
}
catch(KeyNotFoundException ex){
Console.WriteLine(ex.Message);
return new PointF(0.0f,0.0f);
}
}
public int getPrevIndex(int currentIndex){
if(currentIndex == 0){
return this.points.Count - 1;
}
else{
return currentIndex - 1;
}
}
public Hull() {
}
public List<PointF> getPoints(){
return this.points;
}
public Hull(List<PointF> points){
this.pointIndexDict = new Dictionary<PointF, int>();
this.points = points;
//for (int i = 0; i < points.Count;i++){
// pointIndexDict.Add(points[i], i);
//}
}
public void setRightMost(PointF point){
this.rightMostPoint = point;
}
public PointF getRightMost(){
return this.rightMostPoint;
}
public PointF getRightMostPoint(){
PointF rightMost = new PointF();
foreach(PointF point in this.points){
if(point.X > rightMost.X){
rightMost = point;
}
}
return rightMost;
}
public int getRightMostIndex(){
int max = 0;
for (int i = 0; i < points.Count;i++){
if(points[i].X > points[max].X){
max = i;
}
}
return max;
}
public String printPointInfo(int index){
return "[" + points[index].X + ", " + points[index].Y + "]";
}
public int getLeftMostIndex(){
int max = 0;
for (int i = 0; i < points.Count; i++) {
if (points[i].X < points[max].X) {
max = i;
}
}
return max;
}
}
}