Skip to content

Commit

Permalink
implement nearest and farthest and update version -> v0.9.9
Browse files Browse the repository at this point in the history
  • Loading branch information
johnprif committed Feb 18, 2023
1 parent 595ca78 commit 90946c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
49 changes: 36 additions & 13 deletions src/Model/DataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,16 +435,28 @@ private double getAngle(Point2D p, Point2D q, Point2D r)
double c = (r.getX() - p.getX()) * (r.getX() - p.getX()) + (r.getY() - p.getY()) * (r.getY() - p.getY());
return Math.acos((a + b - c) / Math.sqrt(4 * a * b));
}

private Point2D Up(Point2D p)
//for nearest voronoi
private Point2D Up1(Point2D p)
{
Point2D nextP = neighbours.get(p).get(1); //O(1)
double mx = (p.getX() + nextP.getX()) / 2.0;
double my = (p.getY() + nextP.getY()) / 2.0;
double dx = nextP.getY() - p.getY();
double dy = p.getX() - nextP.getX();
double ux = mx + dx/5.0;
double uy = my + dy/5.0;
double ux = mx + dx;
double uy = my + dy;
return new Point2D(ux, uy);
}
//for farthest voronoi
private Point2D Up2(Point2D p)
{
Point2D nextP = neighbours.get(p).get(1); //O(1)
double mx = (p.getX() + nextP.getX()) / 2.0;
double my = (p.getY() + nextP.getY()) / 2.0;
double dx = nextP.getY() - p.getY();
double dy = p.getX() - nextP.getX();
double ux = mx - dx;
double uy = my - dy;
return new Point2D(ux, uy);
}

Expand All @@ -466,13 +478,25 @@ public void addAllUpToK()
int size = getConvexPointsSize();
u_p = new HashMap<Point2D, Point2D>();

for (int i = 0; i < size; i++)
{
Point2D curr = convexPoints.get(i); //O(1)
Point2D Ucurr = Up(curr);
u_p.put(curr, Ucurr);
K.add(Ucurr);
}
if(mode == 1) //nearest voronoi
{
for (int i = 0; i < size; i++)
{
Point2D curr = convexPoints.get(i); //O(1)
Point2D Ucurr = Up1(curr);
u_p.put(curr, Ucurr);
K.add(Ucurr);
}
}else //mode==2 farthest voronoi
{
for (int i = 0; i < size; i++)
{
Point2D curr = convexPoints.get(i); //O(1)
Point2D Ucurr = Up2(curr);
u_p.put(curr, Ucurr);
K.add(Ucurr);
}
}
}

public void addCtoK(Point2D c)
Expand All @@ -485,8 +509,7 @@ public void addCandUtoE(Point2D c, Point2D up)
ArrayList<Point2D> inner = new ArrayList<Point2D>();
inner.add(c);
inner.add(up);
E.add(inner);

E.add(inner);
}

public Point2D getUp(Point2D p)
Expand Down
2 changes: 1 addition & 1 deletion src/View/MainGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MainGUI extends Application
{
private String javaVersion = System.getProperty("java.version");
private String javafxVersion = System.getProperty("javafx.version");
private String version = "v0.9.8";
private String version = "v0.9.9";

private Stage stage;
private Scene scene;
Expand Down

0 comments on commit 90946c2

Please sign in to comment.