com.machinezoo.sourceafis.engine.primitives.IntPoint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sourceafis Show documentation
Show all versions of sourceafis Show documentation
Fingerprint recognition engine that takes a pair of human fingerprint images and returns their similarity score. Supports efficient 1:N search.
// Part of SourceAFIS for Java: https://sourceafis.machinezoo.com/java
package com.machinezoo.sourceafis.engine.primitives;
import java.util.*;
public class IntPoint implements Iterable, Comparable {
public static final IntPoint ZERO = new IntPoint(0, 0);
public static final IntPoint[] EDGE_NEIGHBORS = new IntPoint[] {
new IntPoint(0, -1),
new IntPoint(-1, 0),
new IntPoint(1, 0),
new IntPoint(0, 1)
};
public static final IntPoint[] CORNER_NEIGHBORS = new IntPoint[] {
new IntPoint(-1, -1),
new IntPoint(0, -1),
new IntPoint(1, -1),
new IntPoint(-1, 0),
new IntPoint(1, 0),
new IntPoint(-1, 1),
new IntPoint(0, 1),
new IntPoint(1, 1)
};
public final int x;
public final int y;
public IntPoint(int x, int y) {
this.x = x;
this.y = y;
}
public int area() {
return x * y;
}
public int lengthSq() {
return Integers.sq(x) + Integers.sq(y);
}
public boolean contains(IntPoint other) {
return other.x >= 0 && other.y >= 0 && other.x < x && other.y < y;
}
public IntPoint plus(IntPoint other) {
return new IntPoint(x + other.x, y + other.y);
}
public IntPoint minus(IntPoint other) {
return new IntPoint(x - other.x, y - other.y);
}
public IntPoint negate() {
return new IntPoint(-x, -y);
}
public DoublePoint toDouble() {
return new DoublePoint(x, y);
}
public IntPoint[] lineTo(IntPoint to) {
IntPoint[] result;
IntPoint relative = to.minus(this);
if (Math.abs(relative.x) >= Math.abs(relative.y)) {
result = new IntPoint[Math.abs(relative.x) + 1];
if (relative.x > 0) {
for (int i = 0; i <= relative.x; ++i)
result[i] = new IntPoint(x + i, y + (int)Math.round(i * (relative.y / (double)relative.x)));
} else if (relative.x < 0) {
for (int i = 0; i <= -relative.x; ++i)
result[i] = new IntPoint(x - i, y - (int)Math.round(i * (relative.y / (double)relative.x)));
} else
result[0] = this;
} else {
result = new IntPoint[Math.abs(relative.y) + 1];
if (relative.y > 0) {
for (int i = 0; i <= relative.y; ++i)
result[i] = new IntPoint(x + (int)Math.round(i * (relative.x / (double)relative.y)), y + i);
} else if (relative.y < 0) {
for (int i = 0; i <= -relative.y; ++i)
result[i] = new IntPoint(x - (int)Math.round(i * (relative.x / (double)relative.y)), y - i);
} else
result[0] = this;
}
return result;
}
private List