From 939ab946f3f50ac4581b78de676d3ce1453930c7 Mon Sep 17 00:00:00 2001 From: yeom Date: Sat, 9 Apr 2011 00:24:29 +0000 Subject: [PATCH] having better speedup --- .../src/Benchmarks/oooJava/voronoi/Edge.java | 6 +-- .../Benchmarks/oooJava/voronoi/Vertex.java | 41 ++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Robust/src/Benchmarks/oooJava/voronoi/Edge.java b/Robust/src/Benchmarks/oooJava/voronoi/Edge.java index 4b891344..6e574d58 100644 --- a/Robust/src/Benchmarks/oooJava/voronoi/Edge.java +++ b/Robust/src/Benchmarks/oooJava/voronoi/Edge.java @@ -176,8 +176,7 @@ class Edge { t1 = dest(); lnexta = lNext(); t2 = b.orig(); - Edge e = new Edge(); - ans = e.makeEdge(t1, t2); + ans = makeEdge(t1, t2); ans.splice(lnexta); ans.symmetric().splice(b); return ans; @@ -191,8 +190,7 @@ class Edge { t2 = b.orig(); oprevb = b.oPrev(); - Edge e = new Edge(); - ans = e.makeEdge(t1, t2); + ans = makeEdge(t1, t2); ans.splice(symmetric()); ans.symmetric().splice(oprevb); return ans; diff --git a/Robust/src/Benchmarks/oooJava/voronoi/Vertex.java b/Robust/src/Benchmarks/oooJava/voronoi/Vertex.java index 12314b82..fa5c9e80 100644 --- a/Robust/src/Benchmarks/oooJava/voronoi/Vertex.java +++ b/Robust/src/Benchmarks/oooJava/voronoi/Vertex.java @@ -102,8 +102,7 @@ class Vertex extends Vec2 { } else if (getLeft() == null) { // two points - Edge e = new Edge(); - Edge a = e.makeEdge(this, extra); + Edge a = makeEdge(this, extra); retval = new EdgePair(a, a.symmetric()); } else { // left, !right three points @@ -112,8 +111,8 @@ class Vertex extends Vec2 { Vertex s2 = this; Vertex s3 = extra; Edge e = new Edge(); - Edge a = e.makeEdge(s1, s2); - Edge b = e.makeEdge(s2, s3); + Edge a = makeEdge(s1, s2); + Edge b = makeEdge(s2, s3); a.symmetric().splice(b); Edge c = b.connectLeft(a); if (s1.ccw(s3, s2)) { @@ -162,8 +161,7 @@ class Vertex extends Vec2 { } else if (getLeft() == null) { // two points - Edge e = new Edge(); - Edge a = e.makeEdge(this, extra); + Edge a = makeEdge(this, extra); retval = new EdgePair(a, a.symmetric()); } else { // left, !right three points @@ -171,9 +169,8 @@ class Vertex extends Vec2 { Vertex s1 = getLeft(); Vertex s2 = this; Vertex s3 = extra; - Edge e = new Edge(); - Edge a = e.makeEdge(s1, s2); - Edge b = e.makeEdge(s2, s3); + Edge a = makeEdge(s1, s2); + Edge b = makeEdge(s2, s3); a.symmetric().splice(b); Edge c = b.connectLeft(a); if (s1.ccw(s3, s2)) { @@ -220,8 +217,7 @@ class Vertex extends Vec2 { } else if (getLeft() == null) { // two points - Edge e = new Edge(); - Edge a = e.makeEdge(this, extra); + Edge a = makeEdge(this, extra); retval = new EdgePair(a, a.symmetric()); } else { // left, !right three points @@ -229,9 +225,8 @@ class Vertex extends Vec2 { Vertex s1 = getLeft(); Vertex s2 = this; Vertex s3 = extra; - Edge e = new Edge(); - Edge a = e.makeEdge(s1, s2); - Edge b = e.makeEdge(s2, s3); + Edge a = makeEdge(s1, s2); + Edge b = makeEdge(s2, s3); a.symmetric().splice(b); Edge c = b.connectLeft(a); if (s1.ccw(s3, s2)) { @@ -365,5 +360,23 @@ class Vertex extends Vec2 { double retval = ((double) (Vertex.seed = Vertex.random(Vertex.seed))) / (double) 2147483647; return retval; } + + public Edge makeEdge(Vertex o, Vertex d) { + Edge ql[] = new Edge[4]; + ql[0] = new Edge(ql, 0); + ql[1] = new Edge(ql, 1); + ql[2] = new Edge(ql, 2); + ql[3] = new Edge(ql, 3); + + ql[0].next = ql[0]; + ql[1].next = ql[3]; + ql[2].next = ql[2]; + ql[3].next = ql[1]; + + Edge base = ql[0]; + base.setOrig(o); + base.setDest(d); + return base; + } } -- 2.34.1