]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/utils/geom/LineSegment.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / utils / geom / LineSegment.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.utils.geom;\r
13 \r
14 import java.awt.Rectangle;\r
15 import java.awt.Shape;\r
16 import java.awt.geom.AffineTransform;\r
17 import java.awt.geom.PathIterator;\r
18 import java.awt.geom.Point2D;\r
19 import java.awt.geom.Rectangle2D;\r
20 import java.util.Arrays;\r
21 \r
22 /**\r
23  * Describes a line segment, either linear, quadratic or cubic\r
24  * \r
25  * @author Toni Kalajainen\r
26  */\r
27 public class LineSegment implements Shape {\r
28     private double line[];\r
29     public LineSegment(double x0, double y0, double x1, double y1)\r
30     {\r
31         line = new double[] {x0, y0, x1, y1};\r
32     }\r
33     public LineSegment(double x0, double y0, double x1, double y1, double x2, double y2)\r
34     {\r
35         line = new double[] {x0, y0, x1, y1, x2, y2};\r
36     }\r
37     public LineSegment(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)\r
38     {\r
39         line = new double[] {x0, y0, x1, y1, x2, y2, x3, y3};\r
40     }\r
41     public LineSegment(double data[])\r
42     {\r
43         assert(data.length==4 || data.length==6 || data.length==8);\r
44         line = Arrays.copyOf(data, data.length);\r
45     }\r
46     public double[] getLine() {\r
47         return line;\r
48     }\r
49     public int getDegree() {\r
50         return (line.length-2)/2;\r
51     }\r
52     public Point2D getStartPos(Point2D pt)\r
53     {\r
54         if (pt==null) return new Point2D.Double(line[0], line[1]);\r
55         pt.setLocation(line[0], line[1]);\r
56         return pt;\r
57     }\r
58     public Point2D getEndPos(Point2D pt)\r
59     {\r
60         int p = line.length-2;\r
61         if (pt==null) return new Point2D.Double(line[p], line[p+1]);\r
62         pt.setLocation(line[p], line[p+1]);\r
63         return pt;\r
64     }\r
65     public void setData(double data[])\r
66     {\r
67         assert(data.length==4 || data.length==6 || data.length==8);\r
68         line = Arrays.copyOf(data, data.length);\r
69     }\r
70 \r
71 \r
72 \r
73     @Override\r
74     public boolean contains(Point2D p) {\r
75         return false;\r
76     }\r
77     @Override\r
78     public boolean contains(Rectangle2D r) {\r
79         return false;\r
80     }\r
81     @Override\r
82     public boolean contains(double x, double y) {\r
83         return false;\r
84     }\r
85     @Override\r
86     public boolean contains(double x, double y, double w, double h) {\r
87         return false;\r
88     }\r
89     @Override\r
90     public Rectangle getBounds() {\r
91         return null;\r
92     }\r
93     @Override\r
94     public Rectangle2D getBounds2D() {\r
95         return null;\r
96     }\r
97     @Override\r
98     public PathIterator getPathIterator(AffineTransform at) {\r
99         return null;\r
100     }\r
101     @Override\r
102     public PathIterator getPathIterator(AffineTransform at, double flatness) {\r
103         return null;\r
104     }\r
105     @Override\r
106     public boolean intersects(Rectangle2D r) {\r
107         return false;\r
108     }\r
109     @Override\r
110     public boolean intersects(double x, double y, double w, double h) {\r
111         return false;\r
112     }\r
113 }\r
114 \r