use of de.lmu.ifi.dbs.elki.data.spatial.Polygon in project elki by elki-project.
the class SweepHullDelaunay2D method getHull.
/**
* Get the convex hull only.
*
* Note: if you also want the Delaunay Triangulation, you should get that
* first!
*
* @return Convex hull
*/
public Polygon getHull() {
if (hull == null) {
run(true);
}
DoubleMinMax minmaxX = new DoubleMinMax();
DoubleMinMax minmaxY = new DoubleMinMax();
List<double[]> hullp = new ArrayList<>(hull.size());
for (IntIntPair pair : hull) {
double[] v = points.get(pair.first);
hullp.add(v);
minmaxX.put(v[0]);
minmaxY.put(v[1]);
}
return new Polygon(hullp, minmaxX.getMin(), minmaxX.getMax(), minmaxY.getMin(), minmaxY.getMax());
}
use of de.lmu.ifi.dbs.elki.data.spatial.Polygon in project elki by elki-project.
the class SimplePolygonParser method parseLine.
/**
* Parse a single line.
*
* @return {@code true} if the line was read successful.
*/
private boolean parseLine() {
cureid = null;
curpoly = null;
curlbl = null;
polys.clear();
coords.clear();
labels.clear();
Matcher m = COORD.matcher(reader.getBuffer());
for (; /* initialized by nextLineExceptComments */
tokenizer.valid(); tokenizer.advance()) {
m.region(tokenizer.getStart(), tokenizer.getEnd());
if (m.find()) {
try {
double c1 = ParseUtil.parseDouble(m.group(1));
double c2 = ParseUtil.parseDouble(m.group(2));
if (m.group(3) != null) {
double c3 = ParseUtil.parseDouble(m.group(3));
coords.add(new double[] { c1, c2, c3 });
} else {
coords.add(new double[] { c1, c2 });
}
continue;
} catch (NumberFormatException e) {
LOG.warning("Looked like a coordinate pair but didn't parse: " + tokenizer.getSubstring());
}
}
// Match polygon separator:
// FIXME: Avoid unnecessary subSequence call.
final int len = tokenizer.getEnd() - tokenizer.getStart();
if (//
POLYGON_SEPARATOR.length() == len && reader.getBuffer().subSequence(tokenizer.getStart(), tokenizer.getEnd()).equals(POLYGON_SEPARATOR)) {
if (!coords.isEmpty()) {
polys.add(new Polygon(new ArrayList<>(coords)));
}
continue;
}
String cur = tokenizer.getSubstring();
// First label will become the External ID
if (cureid == null) {
cureid = new ExternalID(cur);
} else {
labels.add(cur);
}
}
// Complete polygon
if (!coords.isEmpty()) {
polys.add(new Polygon(coords));
}
curpoly = new PolygonsObject(polys);
curlbl = (haslabels || !labels.isEmpty()) ? LabelList.make(labels) : null;
return true;
}
Aggregations