| | |
| | | Vector2D baseDir = new Vector2D(longest.end.x - longest.start.x, |
| | | longest.end.y - longest.start.y).normalize(); |
| | | Vector2D perp = baseDir.rotate90CCW(); |
| | | Vector2D baseStartVec = new Vector2D(longest.start.x, longest.start.y); |
| | | double baseProjection = perp.dot(baseStartVec); // keep offsets relative to the longest edge start |
| | | |
| | | Envelope env = safeArea.getEnvelopeInternal(); |
| | | double minProj = perp.dot(new Vector2D(env.getMinX(), env.getMinY())); |
| | | double maxProj = perp.dot(new Vector2D(env.getMaxX(), env.getMaxY())); |
| | | double minProj = Double.POSITIVE_INFINITY; |
| | | double maxProj = Double.NEGATIVE_INFINITY; |
| | | Coordinate[] supportCoords = safeArea.getCoordinates(); |
| | | if (supportCoords != null && supportCoords.length > 0) { |
| | | for (Coordinate coord : supportCoords) { |
| | | double projection = perp.dot(new Vector2D(coord.x, coord.y)) - baseProjection; |
| | | if (projection < minProj) { |
| | | minProj = projection; |
| | | } |
| | | if (projection > maxProj) { |
| | | maxProj = projection; |
| | | } |
| | | } |
| | | } else { |
| | | Envelope env = safeArea.getEnvelopeInternal(); |
| | | minProj = perp.dot(new Vector2D(env.getMinX(), env.getMinY())) - baseProjection; |
| | | maxProj = perp.dot(new Vector2D(env.getMaxX(), env.getMaxY())) - baseProjection; |
| | | } |
| | | if (minProj > maxProj) { |
| | | double tmp = minProj; |
| | | minProj = maxProj; |
| | | maxProj = tmp; |
| | | } |
| | | double first = minProj - width / 2.0; |
| | | |
| | | Geometry originalPoly = createPolygonFromCoordinates(polygon); |