]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/xdot/Shapes.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graphviz / src / org / simantics / graphviz / internal / xdot / Shapes.java
diff --git a/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/xdot/Shapes.java b/bundles/org.simantics.graphviz/src/org/simantics/graphviz/internal/xdot/Shapes.java
new file mode 100644 (file)
index 0000000..0e41c83
--- /dev/null
@@ -0,0 +1,90 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.graphviz.internal.xdot;\r
+\r
+import java.awt.geom.Ellipse2D;\r
+import java.awt.geom.Path2D;\r
+\r
+public class Shapes {\r
+       public static Path2D createPolyline(double[] p) {\r
+               Path2D path = new Path2D.Double();\r
+               path.moveTo(p[0], -p[1]);\r
+               for(int i=2;i<p.length;i+=2)\r
+                       path.lineTo(p[i], -p[i+1]);\r
+               return path;\r
+       }\r
+       \r
+       public static Path2D createPolygon(double[] p) {\r
+               Path2D path = createPolyline(p);\r
+               path.closePath();\r
+               return path;\r
+       }\r
+       \r
+       public static Path2D createBSpline(double[] p) {\r
+               Path2D.Double path = new Path2D.Double();\r
+               path.moveTo(p[0], p[1]);\r
+               double cp2x = 0.5 * (p[2] + p[4]);\r
+               double cp2y = 0.5 * (p[3] + p[5]);\r
+               double newCp1x = (2.0/3.0) * p[4] + (1.0/3.0) * p[6];\r
+               double newCp1y = (2.0/3.0) * p[5] + (1.0/3.0) * p[7];\r
+               path.curveTo(\r
+                               p[2], p[3],\r
+                               cp2x, cp2y,\r
+                               0.5*(cp2x + newCp1x), 0.5*(cp2y + newCp1y)                              \r
+                               );\r
+               for(int i=4;i<p.length-8;i+=2) {\r
+                       double cp1x = newCp1x;\r
+                       double cp1y = newCp1y;\r
+                       cp2x = (1.0/3.0) * p[i] + (2.0/3.0) * p[i+2];\r
+                       cp2y = (1.0/3.0) * p[i+1] + (2.0/3.0) * p[i+3];\r
+                       newCp1x = (2.0/3.0) * p[i+2] + (1.0/3.0) * p[i+4];\r
+                       newCp1y = (2.0/3.0) * p[i+3] + (1.0/3.0) * p[i+5];\r
+                       path.curveTo(\r
+                                       cp1x, cp1y,\r
+                                       cp2x, cp2y,\r
+                                       0.5*(cp2x + newCp1x), 0.5*(cp2y + newCp1y)                              \r
+                                       );      \r
+               }       \r
+               {\r
+                       double cp1x = newCp1x;\r
+                       double cp1y = newCp1y;\r
+                       cp2x = (1.0/3.0) * p[p.length-8] + (2.0/3.0) * p[p.length-6];\r
+                       cp2y = (1.0/3.0) * p[p.length-7] + (2.0/3.0) * p[p.length-5];\r
+                       newCp1x = 0.5 * (p[p.length-6] + p[p.length-4]);\r
+                       newCp1y = 0.5 * (p[p.length-5] + p[p.length-3]);\r
+                       path.curveTo(\r
+                                       cp1x, cp1y,\r
+                                       cp2x, cp2y,\r
+                                       0.5*(cp2x + newCp1x), 0.5*(cp2y + newCp1y)                              \r
+                                       );\r
+                       path.curveTo(\r
+                                       newCp1x, newCp1y,\r
+                                       p[p.length-4], p[p.length-3],\r
+                                       p[p.length-2], p[p.length-1]                            \r
+                                       );\r
+               }\r
+               return path;\r
+       }\r
+       \r
+       public static Path2D createCubicSegments(double[] p) {\r
+               Path2D.Double path = new Path2D.Double();\r
+               path.moveTo(p[0], -p[1]);\r
+               for(int i=2;i<p.length;i+=6) {\r
+                       path.curveTo(p[i],-p[i+1],p[i+2],-p[i+3],p[i+4],-p[i+5]);\r
+               }\r
+               return path;\r
+       }\r
+       \r
+       public static Ellipse2D createEllipse(double x, double y, double w, double h) {\r
+               return new Ellipse2D.Double(x-w, -y-h, w*2.0, h*2.0);\r
+       }\r
+}\r