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