1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.graphviz.internal.xdot;
\r
14 import java.awt.geom.Ellipse2D;
\r
15 import java.awt.geom.Path2D;
\r
17 public class Shapes {
\r
18 public static Path2D createPolyline(double[] p) {
\r
19 Path2D path = new Path2D.Double();
\r
20 path.moveTo(p[0], -p[1]);
\r
21 for(int i=2;i<p.length;i+=2)
\r
22 path.lineTo(p[i], -p[i+1]);
\r
26 public static Path2D createPolygon(double[] p) {
\r
27 Path2D path = createPolyline(p);
\r
32 public static Path2D createBSpline(double[] p) {
\r
33 Path2D.Double path = new Path2D.Double();
\r
34 path.moveTo(p[0], p[1]);
\r
35 double cp2x = 0.5 * (p[2] + p[4]);
\r
36 double cp2y = 0.5 * (p[3] + p[5]);
\r
37 double newCp1x = (2.0/3.0) * p[4] + (1.0/3.0) * p[6];
\r
38 double newCp1y = (2.0/3.0) * p[5] + (1.0/3.0) * p[7];
\r
42 0.5*(cp2x + newCp1x), 0.5*(cp2y + newCp1y)
\r
44 for(int i=4;i<p.length-8;i+=2) {
\r
45 double cp1x = newCp1x;
\r
46 double cp1y = newCp1y;
\r
47 cp2x = (1.0/3.0) * p[i] + (2.0/3.0) * p[i+2];
\r
48 cp2y = (1.0/3.0) * p[i+1] + (2.0/3.0) * p[i+3];
\r
49 newCp1x = (2.0/3.0) * p[i+2] + (1.0/3.0) * p[i+4];
\r
50 newCp1y = (2.0/3.0) * p[i+3] + (1.0/3.0) * p[i+5];
\r
54 0.5*(cp2x + newCp1x), 0.5*(cp2y + newCp1y)
\r
58 double cp1x = newCp1x;
\r
59 double cp1y = newCp1y;
\r
60 cp2x = (1.0/3.0) * p[p.length-8] + (2.0/3.0) * p[p.length-6];
\r
61 cp2y = (1.0/3.0) * p[p.length-7] + (2.0/3.0) * p[p.length-5];
\r
62 newCp1x = 0.5 * (p[p.length-6] + p[p.length-4]);
\r
63 newCp1y = 0.5 * (p[p.length-5] + p[p.length-3]);
\r
67 0.5*(cp2x + newCp1x), 0.5*(cp2y + newCp1y)
\r
71 p[p.length-4], p[p.length-3],
\r
72 p[p.length-2], p[p.length-1]
\r
78 public static Path2D createCubicSegments(double[] p) {
\r
79 Path2D.Double path = new Path2D.Double();
\r
80 path.moveTo(p[0], -p[1]);
\r
81 for(int i=2;i<p.length;i+=6) {
\r
82 path.curveTo(p[i],-p[i+1],p[i+2],-p[i+3],p[i+4],-p[i+5]);
\r
87 public static Ellipse2D createEllipse(double x, double y, double w, double h) {
\r
88 return new Ellipse2D.Double(x-w, -y-h, w*2.0, h*2.0);
\r