Commit ff22c512 authored by Nico Mack's avatar Nico Mack

Minor bug fixes and improvements

parent 5cd35629
......@@ -148,10 +148,12 @@ public class DBScanClusterer<T extends Positionable> implements Clusterer<T> {
int numberOfPoints = points.size();
for (int current = 0; current < numberOfPoints; current++) {
int assignedCLusterId = this.clusterIds.get(current);
Cluster<T> cluster = clustered.get(assignedCLusterId);
cluster.setHandleId(assignedCLusterId);
cluster.addPoint(this.points.get(current));
clustered.set(assignedCLusterId, cluster);
if (assignedCLusterId >= 0) {
Cluster<T> cluster = clustered.get(assignedCLusterId);
cluster.setHandleId(assignedCLusterId);
cluster.addPoint(this.points.get(current));
clustered.set(assignedCLusterId, cluster);
}
}
return clustered;
}
......
......@@ -70,6 +70,8 @@ public class Point extends Float implements Comparable<Point>, Scriptable {
private static final Logger LOGGER = LoggerFactory.getLogger(Point.class.getSimpleName());
private static final String NO_SUCH_AXIS_MESSAGE = "This should never happen! No such axis {}!";
/** Constant identifying the X Axis */
public static final int X_AXIS = 0;
......@@ -562,7 +564,14 @@ public class Point extends Float implements Comparable<Point>, Scriptable {
return (deltaX * deltaX) + (deltaY * deltaY);
}
/** {@inheritDoc} */
/**
* returns the distance between this point and the other one along a given axis. Method returns
* the absolute value of the distance
*
* @param other
* @param axis
* @return
*/
public double getDistance(Point other, int axis) {
double distance = 0;
switch (axis) {
......@@ -573,10 +582,27 @@ public class Point extends Float implements Comparable<Point>, Scriptable {
distance = this.y - other.y;
break;
default:
LOGGER.error("This should never happen! No such axis {}!", axis); //$NON-NLS-1$
LOGGER.error(NO_SUCH_AXIS_MESSAGE, axis);
break;
}
return Math.abs(distance);
}
/** {@inheritDoc} */
public double getSquaredDistance(Point other, int axis) {
double distance = 0;
switch (axis) {
case X_AXIS:
distance = this.x - other.x;
break;
case Y_AXIS:
distance = this.y - other.y;
break;
default:
LOGGER.error(NO_SUCH_AXIS_MESSAGE, axis);
break;
}
return Math.sqrt(distance * distance);
return (distance * distance);
}
/** {@inheritDoc} */
......@@ -630,7 +656,7 @@ public class Point extends Float implements Comparable<Point>, Scriptable {
comparison = PointComparator.y.compare(this, o);
break;
default:
LOGGER.error("This should never happen! No such axis {}!", axis); //$NON-NLS-1$
LOGGER.error(NO_SUCH_AXIS_MESSAGE, axis);
break;
}
}
......
......@@ -40,7 +40,7 @@ public class SquaredDistancePointComparator implements KdComparator<Point> {
/** {@inheritDoc} */
@Override
public double getDistance(Point o1, Point o2, int axis) {
return o1.getDistance(o2, axis);
return o1.getSquaredDistance(o2, axis);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment