Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
indy256 committed Aug 8, 2014
1 parent 224868f commit 9a9a790
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 194 deletions.
51 changes: 24 additions & 27 deletions java/src/DelaunayVoronoi.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Point2D;
import java.awt.geom.*;
import java.util.*;
import java.util.List;
import java.util.Queue;
Expand Down Expand Up @@ -201,7 +201,7 @@ void visitTriangles(TriangleVisitor triVisitor, boolean includeFrame) {
* vertices are a unique set which includes
* all vertices in the subdivision.
* The frame vertices can be included if required.
* <p/>
* <p>
* This is useful for algorithms which require traversing the
* subdivision starting at all vertices.
* Returning a quadedge for each vertex
Expand Down Expand Up @@ -268,7 +268,7 @@ List<Point.Double[]> getTriangles() {
/**
* Gets a List of {@link Polygon}s for the Voronoi cells
* of this triangulation.
* <p/>
* <p>
* The userData of each polygon is set to be the {@link Point.Double)
* of the cell site. This allows easily associating external
* data associated with the sites to the cells.
Expand All @@ -277,8 +277,8 @@ List<Point.Double[]> getTriangles() {
* @return a List of Polygons
*/
List<Point.Double[]> getVoronoiCellPolygons() {
/*
* Compute circumcentres of triangles as vertices for dual edges.
/*
* Compute circumcentres of triangles as vertices for dual edges.
* Precomputing the circumcentres is more efficient,
* and more importantly ensures that the computed centres
* are consistent across the Voronoi cells.
Expand All @@ -295,7 +295,7 @@ List<Point.Double[]> getVoronoiCellPolygons() {
/**
* Gets the Voronoi cell around a site specified
* by the origin of a QuadEdge.
* <p/>
* <p>
* The userData of the polygon is set to be the {@link Point.Double)
* of the site. This allows attaching external
* data associated with the site to this cell polygon.
Expand Down Expand Up @@ -562,21 +562,19 @@ Point.Double dest() {

// visualization
Random rnd = new Random(1);
JPanel panel;
List<Point.Double> points = new ArrayList<>();
List<Point2D.Double[]> tr = Collections.emptyList();
List<Point2D.Double[]> voronoiCellPolygons = Collections.emptyList();

public DelaunayVoronoi() throws HeadlessException {
public DelaunayVoronoi() {
int n = 100;
for (int i = 0; i < n; i++) {
int x = rnd.nextInt(950) + 1;
int y = rnd.nextInt(700) + 1;
Point.Double c = new Point.Double(x, y);
points.add(c);
}

panel = new JPanel() {
setContentPane(new JPanel() {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = ((Graphics2D) g);
Expand All @@ -602,31 +600,26 @@ protected void paintComponent(Graphics g) {
g.drawOval((int) point.x - 2, (int) point.y - 2, 5, 5);
}
}
};
setContentPane(panel);
}

public static void main(String[] args) {
final DelaunayVoronoi dv = new DelaunayVoronoi();
dv.setSize(new Dimension(1024, 768));
dv.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
dv.setVisible(true);
});
setSize(new Dimension(1024, 768));
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
new Thread() {
public void run() {
while (true) {
final Point2D.Double pivot = dv.points.get(0);
pivot.x += dv.rnd.nextInt(4);
pivot.y += dv.rnd.nextInt(2);
final Point2D.Double pivot = points.get(0);
pivot.x += rnd.nextInt(4);
pivot.y += rnd.nextInt(2);
pivot.x %= 950;
pivot.y %= 700;

Set<Point.Double> uniquePoints = new HashSet<>(dv.points);
Set<Point.Double> uniquePoints = new HashSet<>(points);
SubDivision subdivision = new SubDivision(uniquePoints);
for (Point.Double p : uniquePoints) subdivision.insertSite(p);
dv.tr = subdivision.getTriangleCoordinates();
dv.voronoiCellPolygons = subdivision.getVoronoiCellPolygons();
tr = subdivision.getTriangleCoordinates();
voronoiCellPolygons = subdivision.getVoronoiCellPolygons();

dv.panel.repaint();
repaint();
try {
Thread.sleep(15);
} catch (InterruptedException e) {
Expand All @@ -636,4 +629,8 @@ public void run() {
}
}.start();
}
}

public static void main(String[] args) {
new DelaunayVoronoi();
}
}
2 changes: 1 addition & 1 deletion java/src/Inversions.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static int inversions(int[] a, int low, int high) {

// random test
public static void main(String[] args) {
Random rnd = new Random();
Random rnd = new Random(1);
for (int step = 0; step < 1000; step++) {
int n = rnd.nextInt(100);
int[] p = new int[n];
Expand Down
2 changes: 1 addition & 1 deletion java/src/KdTreePointQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ else if (n > k)
}
}

static final Random rnd = new Random();
static final Random rnd = new Random(1);

static int randomizedPartition(Point[] a, int low, int high, boolean divX) {
swap(a, low + rnd.nextInt(high - low), high - 1);
Expand Down
2 changes: 1 addition & 1 deletion java/src/KdTreeRectQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ else if (n > k)
}
}

static final Random rnd = new Random();
static final Random rnd = new Random(1);

static int randomizedPartition(Point[] a, int low, int high, boolean divX) {
swap(a, low + rnd.nextInt(high - low), high - 1);
Expand Down
2 changes: 1 addition & 1 deletion java/src/Lca.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int minPos(int a, int b, int node, int left, int right) {

// Random test
public static void main(String[] args) {
Random rnd = new Random();
Random rnd = new Random(1);
for (int step = 0; step < 1000; step++) {
int n = rnd.nextInt(50) + 1;
List<Integer>[] tree = getRandomTree(n, rnd);
Expand Down
2 changes: 1 addition & 1 deletion java/src/MaxMatchingRandomized.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int rank(int[][] a) {
public static int maxMatching(boolean[][] d) {
int n = d.length;
int[][] a = new int[n][n];
Random rnd = new Random();
Random rnd = new Random(1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (d[i][j]) {
Expand Down
2 changes: 1 addition & 1 deletion java/src/NthElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else if (n > k)
}
}

static Random rnd = new Random();
static Random rnd = new Random(1);

static int randomizedPartition(int[] a, int low, int high) {
swap(a, low + rnd.nextInt(high - low), high - 1);
Expand Down
2 changes: 1 addition & 1 deletion java/src/Partition.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Partition {

static Random rnd = new Random();
static Random rnd = new Random(1);

public static int randomizedPartition(int[] a, int low, int high) {
swap(a, low + rnd.nextInt(high - low), high - 1);
Expand Down
153 changes: 0 additions & 153 deletions java/src/PersistentTreapSet.java

This file was deleted.

6 changes: 4 additions & 2 deletions java/src/PointLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class PointLocation {

public static int[] locatePoints(int[][] polygonX, int[][] polygonY, int[] qx, int[] qy) {
// preprocessing
Map<Long, Integer> endPoints = new HashMap<>();
Map<Integer, NavigableSet<Segment>> verticalSegments = new HashMap<>();
List<Event> events = new ArrayList<>();
Expand All @@ -23,8 +24,8 @@ public static int[] locatePoints(int[][] polygonX, int[][] polygonY, int[] qx, i
}
}
Collections.sort(events, eventComparator);
Treap[] treaps = new Treap[events.size()];
int[] eventsX = new int[events.size()];
Treap[] treaps = new Treap[events.size()];
int cnt = 0;
Treap treap = null;
for (Event event : events) {
Expand All @@ -38,6 +39,7 @@ public static int[] locatePoints(int[][] polygonX, int[][] polygonY, int[] qx, i
eventsX[cnt - 1] = event.x;
treaps[cnt - 1] = treap;
}
// answering queries
int[] res = new int[qx.length];
for (int i = 0; i < qx.length; i++) {
Integer polygonId = endPoints.get(((long) qx[i] << 32) + qy[i]);
Expand Down Expand Up @@ -146,7 +148,7 @@ static long cross(long ax, long ay, long bx, long by, long cx, long cy) {
return (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
}

static Random random = new Random();
static Random random = new Random(1);

// persistent treap
static class Treap {
Expand Down
2 changes: 1 addition & 1 deletion java/src/PointLocationOffline.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static long cross(long ax, long ay, long bx, long by, long cx, long cy) {
return (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
}

static Random random = new Random();
static Random random = new Random(1);

static class Treap {
Segment key;
Expand Down
Loading

0 comments on commit 9a9a790

Please sign in to comment.