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