use of org.twak.viewTrace.QuadTree.AxisAlignedBoundingBox in project chordatlas by twak.
the class GBias method getAngle.
/**
* local bias
*/
public Double getAngle(Line line, Point2d cen) {
final double PI8 = Math.PI / 8;
DRectangle r = new DRectangle(line);
r.grow(expand);
Collection<Longer> res = tree.queryRange(r);
double bestScore = -Double.MAX_VALUE;
Double bestAngle = null;
for (AxisAlignedBoundingBox aabb : res) {
Line gis = ((Longer) aabb).line;
double len = gis.length();
// gis.distance( line );
double dist = gis.fromPPram(0.5).distance(line.fromPPram(0.5));
if (dist < len * expand) {
double angle = line.absAngle(gis);
if (angle < PI8) {
double score = (PI8 - angle) / dist;
if (score > bestScore) {
bestAngle = gis.aTan2();
bestScore = score;
}
} else if (Mathz.inRangeTol(angle, Mathz.PI2, PI8)) {
double score = 0.2 * (PI8 - angle) / dist;
if (score > bestScore) {
gis = new Line(new Point2d(gis.start.y, -gis.start.x), new Point2d(gis.end.y, -gis.end.x));
if (gis.absAngle(line) > PI8)
gis = gis.reverse();
bestAngle = gis.aTan2();
bestScore = score;
}
}
}
}
if (bestAngle != null)
return bestAngle;
else
return null;
}
Aggregations