}
}
if (ridgeDirection == null) {
LineSegmentXZ longestSeg = MinMaxUtil.max(
simplifiedPolygon.getSegments(),
new Function<LineSegmentXZ, Double>() {
public Double apply(LineSegmentXZ s) {
return s.getLength();
};
});
ridgeDirection =
longestSeg.p2.subtract(longestSeg.p1).normalize();
if (area.getTags().contains("roof:orientation", "across")) {
ridgeDirection = ridgeDirection.rightNormal();
}
}
/* calculate the two outermost intersections of the
* quasi-infinite ridge line with segments of the polygon */
VectorXZ p1 = outerPoly.getCentroid();
Collection<LineSegmentXZ> intersections =
simplifiedPolygon.intersectionSegments(new LineSegmentXZ(
p1.add(ridgeDirection.mult(-1000)),
p1.add(ridgeDirection.mult(1000))
));
if (intersections.size() < 2) {
throw new InvalidGeometryException(
"cannot handle roof geometry for id "
+ area.getOsmObject().id);
}
//TODO choose outermost instead of any pair of intersections
Iterator<LineSegmentXZ> it = intersections.iterator();
cap1 = it.next();
cap2 = it.next();
/* base ridge on the centers of the intersected segments
* (the intersections itself are not used because the
* tagged ridge direction is likely not precise) */
VectorXZ c1 = cap1.getCenter();
VectorXZ c2 = cap2.getCenter();
ridgeOffset = min(
cap1.getLength() * relativeRoofOffset,
0.4 * c1.distanceTo(c2));
if (relativeRoofOffset == 0) {
ridge = new LineSegmentXZ(c1, c2);
} else {
ridge = new LineSegmentXZ(
c1.add( p1.subtract(c1).normalize().mult(ridgeOffset) ),
c2.add( p1.subtract(c2).normalize().mult(ridgeOffset) ));
}