diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/math/geometry')
6 files changed, 43 insertions, 26 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/math/geometry/AlphaShape.java b/src/de/lmu/ifi/dbs/elki/math/geometry/AlphaShape.java index 1ab324c3..11f24cb2 100644 --- a/src/de/lmu/ifi/dbs/elki/math/geometry/AlphaShape.java +++ b/src/de/lmu/ifi/dbs/elki/math/geometry/AlphaShape.java @@ -12,7 +12,7 @@ import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -64,11 +64,11 @@ public class AlphaShape { // Compute delaunay triangulation: delaunay = (new SweepHullDelaunay2D(points)).getDelaunay(); - List<Polygon> polys = new ArrayList<Polygon>(); + List<Polygon> polys = new ArrayList<>(); // Working data BitSet used = new BitSet(delaunay.size()); - List<Vector> cur = new ArrayList<Vector>(); + List<Vector> cur = new ArrayList<>(); for(int i = 0 /* = used.nextClearBit(0) */; i < delaunay.size() && i >= 0; i = used.nextClearBit(i + 1)) { if(!used.get(i)) { @@ -82,7 +82,7 @@ public class AlphaShape { } if(cur.size() > 0) { polys.add(new Polygon(cur)); - cur = new ArrayList<Vector>(); + cur = new ArrayList<>(); } } } diff --git a/src/de/lmu/ifi/dbs/elki/math/geometry/GrahamScanConvexHull2D.java b/src/de/lmu/ifi/dbs/elki/math/geometry/GrahamScanConvexHull2D.java index def48c52..c2945fde 100644 --- a/src/de/lmu/ifi/dbs/elki/math/geometry/GrahamScanConvexHull2D.java +++ b/src/de/lmu/ifi/dbs/elki/math/geometry/GrahamScanConvexHull2D.java @@ -76,7 +76,7 @@ public class GrahamScanConvexHull2D { * Constructor.
*/
public GrahamScanConvexHull2D() {
- this.points = new LinkedList<Vector>();
+ this.points = new LinkedList<>();
}
/**
@@ -86,7 +86,7 @@ public class GrahamScanConvexHull2D { */
public void add(Vector point) {
if(this.ok) {
- this.points = new LinkedList<Vector>(this.points);
+ this.points = new LinkedList<>(this.points);
this.ok = false;
}
this.points.add(point);
@@ -229,7 +229,7 @@ public class GrahamScanConvexHull2D { return;
}
Iterator<Vector> iter = points.iterator();
- Stack<Vector> stack = new Stack<Vector>();
+ Stack<Vector> stack = new Stack<>();
// Start with the first two points on the stack
stack.add(iter.next());
stack.add(iter.next());
diff --git a/src/de/lmu/ifi/dbs/elki/math/geometry/PrimsMinimumSpanningTree.java b/src/de/lmu/ifi/dbs/elki/math/geometry/PrimsMinimumSpanningTree.java index d6675256..de31f92e 100644 --- a/src/de/lmu/ifi/dbs/elki/math/geometry/PrimsMinimumSpanningTree.java +++ b/src/de/lmu/ifi/dbs/elki/math/geometry/PrimsMinimumSpanningTree.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.math.geometry; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -42,6 +42,8 @@ import de.lmu.ifi.dbs.elki.utilities.documentation.Reference; * </p> * * @author Erich Schubert + * + * @apiviz.uses Adapter */ @Reference(authors = "R. C. Prim", title = "Shortest connection networks and some generalizations", booktitle = "Bell System Technical Journal, 36 (1957)") public class PrimsMinimumSpanningTree { diff --git a/src/de/lmu/ifi/dbs/elki/math/geometry/SweepHullDelaunay2D.java b/src/de/lmu/ifi/dbs/elki/math/geometry/SweepHullDelaunay2D.java index afb8db26..ca6d0e5e 100644 --- a/src/de/lmu/ifi/dbs/elki/math/geometry/SweepHullDelaunay2D.java +++ b/src/de/lmu/ifi/dbs/elki/math/geometry/SweepHullDelaunay2D.java @@ -21,7 +21,7 @@ import de.lmu.ifi.dbs.elki.utilities.pairs.IntIntPair; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -113,7 +113,7 @@ public class SweepHullDelaunay2D { throw new UnsupportedOperationException("There is no delaunay triangulation for less than three objects!"); } int len = points.size() - 1; - hull = new LinkedList<IntIntPair>(); + hull = new LinkedList<>(); tris = hullonly ? null : new ArrayList<Triangle>(len); final Vector seed; @@ -614,7 +614,7 @@ public class SweepHullDelaunay2D { } DoubleMinMax minmaxX = new DoubleMinMax(); DoubleMinMax minmaxY = new DoubleMinMax(); - List<Vector> hullp = new ArrayList<Vector>(hull.size()); + List<Vector> hullp = new ArrayList<>(hull.size()); for(IntIntPair pair : hull) { Vector v = points.get(pair.first); hullp.add(v); diff --git a/src/de/lmu/ifi/dbs/elki/math/geometry/XYCurve.java b/src/de/lmu/ifi/dbs/elki/math/geometry/XYCurve.java index 3a53f2a2..36ee7f23 100644 --- a/src/de/lmu/ifi/dbs/elki/math/geometry/XYCurve.java +++ b/src/de/lmu/ifi/dbs/elki/math/geometry/XYCurve.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.math.geometry; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -151,7 +151,7 @@ public class XYCurve implements Result, TextWriteable { public void addAndSimplify(double x, double y) { // simplify curve when possible: final int len = data.size(); - if(len >= 4) { + if (len >= 4) { // Look at the previous 2 points final double l1x = data.get(len - 4); final double l1y = data.get(len - 3); @@ -163,16 +163,16 @@ public class XYCurve implements Result, TextWriteable { final double cdx = x - l2x; final double cdy = y - l2y; // X simplification - if((ldx == 0) && (cdx == 0)) { + if ((ldx == 0) && (cdx == 0)) { data.remove(len - 2, 2); } // horizontal simplification - else if((ldy == 0) && (cdy == 0)) { + else if ((ldy == 0) && (cdy == 0)) { data.remove(len - 2, 2); } // diagonal simplification - else if(ldy > 0 && cdy > 0) { - if(Math.abs((ldx / ldy) - (cdx / cdy)) < THRESHOLD) { + else if (ldy > 0 && cdy > 0) { + if (Math.abs((ldx / ldy) - (cdx / cdy)) < THRESHOLD) { data.remove(len - 2, 2); } } @@ -255,6 +255,21 @@ public class XYCurve implements Result, TextWriteable { } /** + * Rescale the graph. + * + * @param sx Scaling factor for X axis + * @param sy Scaling factor for Y axis + */ + public void rescale(double sx, double sy) { + for (int i = 0; i < data.size(); i += 2) { + data.set(i, sx * data.get(i)); + data.set(i + 1, sy * data.get(i + 1)); + } + maxx *= sx; + maxy *= sy; + } + + /** * Size of curve. * * @return curve length @@ -294,7 +309,7 @@ public class XYCurve implements Result, TextWriteable { out.commentPrint(" "); out.commentPrint(labely); out.flush(); - for(int pos = 0; pos < data.size(); pos+=2) { + for (int pos = 0; pos < data.size(); pos += 2) { out.inlinePrint(Double.toString(data.get(pos))); out.inlinePrint(Double.toString(data.get(pos + 1))); out.flush(); @@ -306,7 +321,7 @@ public class XYCurve implements Result, TextWriteable { StringBuilder buf = new StringBuilder(); buf.append("XYCurve["); buf.append(labelx).append(',').append(labely).append(':'); - for(int pos = 0; pos < data.size(); pos += 2) { + for (int pos = 0; pos < data.size(); pos += 2) { buf.append(' ').append(data.get(pos)).append(',').append(data.get(pos + 1)); } buf.append(']'); @@ -334,21 +349,21 @@ public class XYCurve implements Result, TextWriteable { public static double areaUnderCurve(XYCurve curve) { TDoubleArrayList data = curve.data; double prevx = data.get(0), prevy = data.get(1); - if(prevx > curve.minx) { + if (prevx > curve.minx) { throw new UnsupportedOperationException("Curves must be monotone on X for areaUnderCurve to be valid."); } double area = 0.0; - for(int pos = 2; pos < data.size(); pos += 2) { + for (int pos = 2; pos < data.size(); pos += 2) { final double curx = data.get(pos), cury = data.get(pos + 1); - if(prevx > curx) { + if (prevx > curx) { throw new UnsupportedOperationException("Curves must be monotone on X for areaUnderCurve to be valid."); } area += (curx - prevx) * (prevy + cury) * .5; // .5 = mean Y prevx = curx; prevy = cury; } - if(prevx < curve.maxx) { - throw new UnsupportedOperationException("Curves must be monotone on X for areaUnderCurve to be valid."); + if (prevx < curve.maxx) { + throw new UnsupportedOperationException("Curves must be complete on X for areaUnderCurve to be valid."); } return area; } @@ -415,4 +430,4 @@ public class XYCurve implements Result, TextWriteable { return pos < data.size(); } } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/math/geometry/package-info.java b/src/de/lmu/ifi/dbs/elki/math/geometry/package-info.java index a7bb6e6e..d94ac05a 100644 --- a/src/de/lmu/ifi/dbs/elki/math/geometry/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/math/geometry/package-info.java @@ -5,7 +5,7 @@ This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures -Copyright (C) 2012 +Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team |