From 90946c2a5ddb7b311c022621cb0ce258ac705b39 Mon Sep 17 00:00:00 2001 From: johnprif Date: Sat, 18 Feb 2023 14:09:07 +0200 Subject: [PATCH] implement nearest and farthest and update version -> v0.9.9 --- src/Model/DataBase.java | 49 ++++++++++++++++++++++++++++++----------- src/View/MainGUI.java | 2 +- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/Model/DataBase.java b/src/Model/DataBase.java index baaf0a2..3df3507 100644 --- a/src/Model/DataBase.java +++ b/src/Model/DataBase.java @@ -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); } @@ -466,13 +478,25 @@ public void addAllUpToK() int size = getConvexPointsSize(); u_p = new HashMap(); - 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) @@ -485,8 +509,7 @@ public void addCandUtoE(Point2D c, Point2D up) ArrayList inner = new ArrayList(); inner.add(c); inner.add(up); - E.add(inner); - + E.add(inner); } public Point2D getUp(Point2D p) diff --git a/src/View/MainGUI.java b/src/View/MainGUI.java index f496eda..4d39349 100644 --- a/src/View/MainGUI.java +++ b/src/View/MainGUI.java @@ -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;