Commit 667e12b3 authored by Nico Mack's avatar Nico Mack

Added possibility to specify gridAngle and gridRowOffset parameters when

generating point clouds for shape
parent cf0482c2
......@@ -502,22 +502,19 @@ public class ShapeUtils {
long elapsed = System.currentTimeMillis();
Map<Point, Point> startPoints = new TreeMap<>();
TreeMap<Point, Point> startPoints = new TreeMap<>();
for (Segment segment : segments) {
Point start = segment.getStart();
Point end = segment.getEnd();
if (startPoints.containsKey(start)) {
continue;
}
startPoints.put(start, end);
}
Point start = startPoints.keySet().iterator().next();
Point start = startPoints.firstKey();
boolean abort = false;
do {
Point end = startPoints.get(start);
Segment segment = new Segment(start, end);
......@@ -529,16 +526,10 @@ public class ShapeUtils {
}
} while ((daisyChained.size() < segments.size()) && !abort);
if (abort) {
// LOGGER.warn("Daisy chaining aborted!");
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Daisy chaining of segments took {} ms!", System.currentTimeMillis() - elapsed); //$NON-NLS-1$
}
return daisyChained;
}
......@@ -1148,6 +1139,22 @@ public class ShapeUtils {
return minimalBBox;
}
// ---------------------------------------------------------------------------
/**
* @param shape
* @param angle
* @return
*/
// ---------------------------------------------------------------------------
public static BoundingBox getBoundingBoxAtAngle(Shape shape, double angle) {
Point centre = centroidOf(shape);
AffineTransform rotation = AffineTransform.getRotateInstance(angle, centre.getX(), centre.getY());
Shape rotated = rotation.createTransformedShape(shape);
return new BoundingBox(rotated.getBounds2D(), 0);
}
// ---------------------------------------------------------------------------
/**
* @param shape
......@@ -1156,10 +1163,16 @@ public class ShapeUtils {
*/
// ---------------------------------------------------------------------------
public static List<Point> generatePointCloud(Shape shape, int spacing) {
public static List<Point> generatePointCloud(Shape shape, int spacing, int rowOffset, double angle) {
Point centre = centroidOf(shape);
BoundingBox bbox = getMinimalBoundingBox(shape);
BoundingBox bbox;
if (Double.isNaN(angle)) {
bbox = getMinimalBoundingBox(shape);
} else {
bbox = getBoundingBoxAtAngle(shape, angle);
}
double halfMajorAxis = bbox.getBounds().getWidth() / 2;
double halfMinorAxis = bbox.getBounds().getHeight() / 2;
......@@ -1169,8 +1182,12 @@ public class ShapeUtils {
List<Point> pointCloud = new ArrayList<>(numberOfPoints);
AffineTransform rotation = AffineTransform.getRotateInstance(-bbox.getAngle());
double offset = -rowOffset;
for (double y = -halfMinorAxis; y < halfMinorAxis; y += spacing) {
for (double x = -halfMajorAxis; x < halfMajorAxis; x += spacing) {
offset = (offset < spacing) ? offset + rowOffset : -rowOffset;
for (double x = -halfMajorAxis + offset; x < halfMajorAxis; x += spacing) {
Point candidate = new Point((float) x, (float) y, 0f, ScreenCoordinates.class);
Point rotated = candidate.clone();
rotation.transform(candidate, rotated);
......
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