]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/utils/geom/LineSegment.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/utils/geom/LineSegment.java
new file mode 100644 (file)
index 0000000..6e52dfa
--- /dev/null
@@ -0,0 +1,114 @@
+/*******************************************************************************\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.g2d.utils.geom;\r
+\r
+import java.awt.Rectangle;\r
+import java.awt.Shape;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.PathIterator;\r
+import java.awt.geom.Point2D;\r
+import java.awt.geom.Rectangle2D;\r
+import java.util.Arrays;\r
+\r
+/**\r
+ * Describes a line segment, either linear, quadratic or cubic\r
+ * \r
+ * @author Toni Kalajainen\r
+ */\r
+public class LineSegment implements Shape {\r
+    private double line[];\r
+    public LineSegment(double x0, double y0, double x1, double y1)\r
+    {\r
+        line = new double[] {x0, y0, x1, y1};\r
+    }\r
+    public LineSegment(double x0, double y0, double x1, double y1, double x2, double y2)\r
+    {\r
+        line = new double[] {x0, y0, x1, y1, x2, y2};\r
+    }\r
+    public LineSegment(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)\r
+    {\r
+        line = new double[] {x0, y0, x1, y1, x2, y2, x3, y3};\r
+    }\r
+    public LineSegment(double data[])\r
+    {\r
+        assert(data.length==4 || data.length==6 || data.length==8);\r
+        line = Arrays.copyOf(data, data.length);\r
+    }\r
+    public double[] getLine() {\r
+        return line;\r
+    }\r
+    public int getDegree() {\r
+        return (line.length-2)/2;\r
+    }\r
+    public Point2D getStartPos(Point2D pt)\r
+    {\r
+        if (pt==null) return new Point2D.Double(line[0], line[1]);\r
+        pt.setLocation(line[0], line[1]);\r
+        return pt;\r
+    }\r
+    public Point2D getEndPos(Point2D pt)\r
+    {\r
+        int p = line.length-2;\r
+        if (pt==null) return new Point2D.Double(line[p], line[p+1]);\r
+        pt.setLocation(line[p], line[p+1]);\r
+        return pt;\r
+    }\r
+    public void setData(double data[])\r
+    {\r
+        assert(data.length==4 || data.length==6 || data.length==8);\r
+        line = Arrays.copyOf(data, data.length);\r
+    }\r
+\r
+\r
+\r
+    @Override\r
+    public boolean contains(Point2D p) {\r
+        return false;\r
+    }\r
+    @Override\r
+    public boolean contains(Rectangle2D r) {\r
+        return false;\r
+    }\r
+    @Override\r
+    public boolean contains(double x, double y) {\r
+        return false;\r
+    }\r
+    @Override\r
+    public boolean contains(double x, double y, double w, double h) {\r
+        return false;\r
+    }\r
+    @Override\r
+    public Rectangle getBounds() {\r
+        return null;\r
+    }\r
+    @Override\r
+    public Rectangle2D getBounds2D() {\r
+        return null;\r
+    }\r
+    @Override\r
+    public PathIterator getPathIterator(AffineTransform at) {\r
+        return null;\r
+    }\r
+    @Override\r
+    public PathIterator getPathIterator(AffineTransform at, double flatness) {\r
+        return null;\r
+    }\r
+    @Override\r
+    public boolean intersects(Rectangle2D r) {\r
+        return false;\r
+    }\r
+    @Override\r
+    public boolean intersects(double x, double y, double w, double h) {\r
+        return false;\r
+    }\r
+}\r
+\r