Patch by Stefan, needed for JCP-prim, available from 0-other from:
http://pele.farmbio.uu.se/cgi-bin/gitweb.cgi?p=jchempaint-primary.git;a=summary
diff --git a/src/main/org/openscience/cdk/geometry/GeometryTools.java b/src/main/org/openscience/cdk/geometry/GeometryTools.java
index 4ec2e6e..b5c1576 100644 (file)
--- a/src/main/org/openscience/cdk/geometry/GeometryTools.java
+++ b/src/main/org/openscience/cdk/geometry/GeometryTools.java
@@ -38,6 +38,7 @@ import javax.vecmath.Point3d;
import javax.vecmath.Vector2d;
import javax.vecmath.Vector3d;
import java.awt.;
+import java.awt.geom.Rectangle2D;
import java.util.;
import java.util.List;
@@ -1452,4 +1453,31 @@ public class GeometryTools {
}
return bondLengthSum / bondCounter;
}
+
+
+ /*
+ * Shift the container so that it does not overlap with the previous.
+ * XXX this is a very crude layout technique!
+ * @param container the atom container to shift
+ * @param bounds the bounds of the atom container to shift
+ * @param last the bounds of the last atom container
+ /
+ public static Rectangle2D shiftContainer(
+ IAtomContainer container, Rectangle2D bounds, Rectangle2D last, double gap) {
+
+ if (bounds.intersects(last)) {
+
+ // XXX always displace across width - could be improved
+ double d = bounds.getWidth() + last.getWidth() + gap;
+
+ Point2d p = new Point2d(last.getCenterX() + d, last.getCenterY());
+ GeometryTools.translate2DCenterTo(container, p);
+ return new Rectangle2D.Double(bounds.getX() + d,
+ bounds.getY(),
+ bounds.getWidth(),
+ bounds.getHeight());
+ } else {
+ return bounds;
+ }
+ }
}
I have since rewritten the patch to address some shortcomings (IMHO):
http://pele.farmbio.uu.se/cgi-bin/gitweb.cgi?p=cdk-jchempaint.git;a=commit;h=eebc7c0da09ace8406de8163091e460580409f9c
Such as:
Attached patch fails to apply
pplying: Reimplemented shiftContainer(IAtomContainer, Rectangle2D, Rectange2D, double) originally implemented as jchempaint-primary patch 9200bdc4d68dc8f70373a62eaec51357b680d5e6 by Stefan Kuhn: fixing the detection of overlap, and added missing unit tests
error: patch failed: src/main/org/openscience/cdk/geometry/GeometryTools.java:1467
error: src/main/org/openscience/cdk/geometry/GeometryTools.java: patch does not apply
error: patch failed: src/test/org/openscience/cdk/geometry/GeometryToolsTest.java:512
error: src/test/org/openscience/cdk/geometry/GeometryToolsTest.java: patch does not apply
Patch failed at 0001 Reimplemented shiftContainer(IAtomContainer, Rectangle2D, Rectange2D, double) originally implemented as jchempaint-primary patch 9200bdc4d68dc8f70373a62eaec51357b680d5e6 by Stefan Kuhn: fixing the detection of overlap, and added missing unit tests
Updated mbox patch to cleanly apply to master...
patch looks good. Applied to master