import
java.util.*;
class
Point
implements
Comparable<Point> {
double
x, y;
public
Point(
double
x,
double
y) {
this
.x = x;
this
.y = y;
}
@Override
public
int
compareTo(Point other) {
return
Double.compare(
this
.x, other.x);
}
}
class
Region {
Point site;
List<Point> vertices;
public
Region(Point site, List<Point> vertices) {
this
.site = site;
this
.vertices = vertices;
}
}
class
Event
implements
Comparable<Event> {
Point point;
int
index;
boolean
isSite;
public
Event(Point point,
int
index,
boolean
isSite) {
this
.point = point;
this
.index = index;
this
.isSite = isSite;
}
@Override
public
int
compareTo(Event other) {
if
(
this
.point.x == other.point.x) {
return
this
.isSite ? -
1
:
1
;
}
return
Double.compare(
this
.point.x, other.point.x);
}
}
public
class
VoronoiSweepLine {
public
static
List<Region> voronoiSweepLine(List<Point> points) {
int
n = points.size();
List<Region> regions =
new
ArrayList<>();
Collections.sort(points);
TreeSet<Event> eventQueue =
new
TreeSet<>();
for
(
int
i =
0
; i < n; i++) {
eventQueue.add(
new
Event(points.get(i), i,
true
));
}
while
(!eventQueue.isEmpty()) {
Event currentEvent = eventQueue.pollFirst();
if
(currentEvent.isSite) {
}
else
{
}
regions.add(
new
Region(
new
Point(
0
,
0
),
new
ArrayList<>()));
}
return
regions;
}
public
static
void
main(String[] args) {
List<Point> points = Arrays.asList(
new
Point(
2
,
5
),
new
Point(
4
,
5
),
new
Point(
7
,
2
),
new
Point(
5
,
7
)
);
List<Region> voronoiRegions = voronoiSweepLine(points);
for
(
int
i =
0
; i < voronoiRegions.size(); i++) {
Region region = voronoiRegions.get(i);
System.out.println(
"Voronoi Region #"
+ (i +
1
) +
": Site ("
+ region.site.x +
", "
+ region.site.y +
")"
);
for
(Point vertex : region.vertices) {
System.out.println(
"Vertex ("
+ vertex.x +
", "
+ vertex.y +
")"
);
}
System.out.println();
}
}
}