]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/profile/LineUtilities.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / profile / LineUtilities.java
index 73ad05851d9689c8a75a15adbd89367e825cac1f..86e0bf7ed69ca9d1148f31c95fb6e1fd7c246f56 100644 (file)
-package org.simantics.diagram.profile;\r
-/* \r
- * JFreeChart : a free chart library for the Java(tm) platform\r
- * \r
- *\r
- * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.\r
- *\r
- * Project Info:  http://www.jfree.org/jfreechart/index.html\r
- *\r
- * This library is free software; you can redistribute it and/or modify it\r
- * under the terms of the GNU Lesser General Public License as published by\r
- * the Free Software Foundation; either version 2.1 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful, but\r
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public\r
- * License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,\r
- * USA.\r
- *\r
- * [Java is a trademark or registered trademark of Sun Microsystems, Inc.\r
- * in the United States and other countries.]\r
- *\r
- * ------------------\r
- * LineUtilities.java\r
- * ------------------\r
- * (C) Copyright 2008, by Object Refinery Limited and Contributors.\r
- *\r
- * Original Author:  David Gilbert (for Object Refinery Limited);\r
- * Contributor(s):   -;\r
- *\r
- * Changes\r
- * -------\r
- * 05-Nov-2008 : Version 1 (DG);\r
- *\r
- */\r
-\r
-import java.awt.geom.Line2D;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-/**\r
- * Some utility methods for {@link Line2D} objects.\r
- *\r
- * @since 1.0.12\r
- */\r
-public class LineUtilities {\r
-\r
-    /**\r
-     * Clips the specified line to the given rectangle.\r
-     *\r
-     * @param line  the line (<code>null</code> not permitted).\r
-     * @param rect  the clipping rectangle (<code>null</code> not permitted).\r
-     *\r
-     * @return <code>true</code> if the clipped line is visible, and\r
-     *     <code>false</code> otherwise.\r
-     */\r
-    public static boolean clipLine(Line2D line, Rectangle2D rect) {\r
-\r
-        double x1 = line.getX1();\r
-        double y1 = line.getY1();\r
-        double x2 = line.getX2();\r
-        double y2 = line.getY2();\r
-\r
-        double minX = rect.getMinX();\r
-        double maxX = rect.getMaxX();\r
-        double minY = rect.getMinY();\r
-        double maxY = rect.getMaxY();\r
-\r
-        int f1 = rect.outcode(x1, y1);\r
-        int f2 = rect.outcode(x2, y2);\r
-\r
-        while ((f1 | f2) != 0) {\r
-            if ((f1 & f2) != 0) {\r
-                return false;\r
-            }\r
-            double dx = (x2 - x1);\r
-            double dy = (y2 - y1);\r
-            // update (x1, y1), (x2, y2) and f1 and f2 using intersections\r
-            // then recheck\r
-            if (f1 != 0) {\r
-                // first point is outside, so we update it against one of the\r
-                // four sides then continue\r
-                if ((f1 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT\r
-                        && dx != 0.0) {\r
-                    y1 = y1 + (minX - x1) * dy / dx;\r
-                    x1 = minX;\r
-                }\r
-                else if ((f1 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT\r
-                        && dx != 0.0) {\r
-                    y1 = y1 + (maxX - x1) * dy / dx;\r
-                    x1 = maxX;\r
-                }\r
-                else if ((f1 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM\r
-                        && dy != 0.0) {\r
-                    x1 = x1 + (maxY - y1) * dx / dy;\r
-                    y1 = maxY;\r
-                }\r
-                else if ((f1 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP\r
-                        && dy != 0.0) {\r
-                    x1 = x1 + (minY - y1) * dx / dy;\r
-                    y1 = minY;\r
-                }\r
-                f1 = rect.outcode(x1, y1);\r
-            }\r
-            else if (f2 != 0) {\r
-                // second point is outside, so we update it against one of the\r
-                // four sides then continue\r
-                if ((f2 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT\r
-                        && dx != 0.0) {\r
-                    y2 = y2 + (minX - x2) * dy / dx;\r
-                    x2 = minX;\r
-                }\r
-                else if ((f2 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT\r
-                        && dx != 0.0) {\r
-                    y2 = y2 + (maxX - x2) * dy / dx;\r
-                    x2 = maxX;\r
-                }\r
-                else if ((f2 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM\r
-                        && dy != 0.0) {\r
-                    x2 = x2 + (maxY - y2) * dx / dy;\r
-                    y2 = maxY;\r
-                }\r
-                else if ((f2 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP\r
-                        && dy != 0.0) {\r
-                    x2 = x2 + (minY - y2) * dx / dy;\r
-                    y2 = minY;\r
-                }\r
-                f2 = rect.outcode(x2, y2);\r
-            }\r
-        }\r
-\r
-        line.setLine(x1, y1, x2, y2);\r
-        return true;  // the line is visible - if it wasn't, we'd have\r
-                      // returned false from within the while loop above\r
-\r
-    }\r
-\r
+package org.simantics.diagram.profile;
+/* 
+ * JFreeChart : a free chart library for the Java(tm) platform
+ * 
+ *
+ * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
+ *
+ * Project Info:  http://www.jfree.org/jfreechart/index.html
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ *
+ * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
+ * in the United States and other countries.]
+ *
+ * ------------------
+ * LineUtilities.java
+ * ------------------
+ * (C) Copyright 2008, by Object Refinery Limited and Contributors.
+ *
+ * Original Author:  David Gilbert (for Object Refinery Limited);
+ * Contributor(s):   -;
+ *
+ * Changes
+ * -------
+ * 05-Nov-2008 : Version 1 (DG);
+ *
+ */
+
+import java.awt.geom.Line2D;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * Some utility methods for {@link Line2D} objects.
+ *
+ * @since 1.0.12
+ */
+public class LineUtilities {
+
+    /**
+     * Clips the specified line to the given rectangle.
+     *
+     * @param line  the line (<code>null</code> not permitted).
+     * @param rect  the clipping rectangle (<code>null</code> not permitted).
+     *
+     * @return <code>true</code> if the clipped line is visible, and
+     *     <code>false</code> otherwise.
+     */
+    public static boolean clipLine(Line2D line, Rectangle2D rect) {
+
+        double x1 = line.getX1();
+        double y1 = line.getY1();
+        double x2 = line.getX2();
+        double y2 = line.getY2();
+
+        double minX = rect.getMinX();
+        double maxX = rect.getMaxX();
+        double minY = rect.getMinY();
+        double maxY = rect.getMaxY();
+
+        int f1 = rect.outcode(x1, y1);
+        int f2 = rect.outcode(x2, y2);
+
+        while ((f1 | f2) != 0) {
+            if ((f1 & f2) != 0) {
+                return false;
+            }
+            double dx = (x2 - x1);
+            double dy = (y2 - y1);
+            // update (x1, y1), (x2, y2) and f1 and f2 using intersections
+            // then recheck
+            if (f1 != 0) {
+                // first point is outside, so we update it against one of the
+                // four sides then continue
+                if ((f1 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT
+                        && dx != 0.0) {
+                    y1 = y1 + (minX - x1) * dy / dx;
+                    x1 = minX;
+                }
+                else if ((f1 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT
+                        && dx != 0.0) {
+                    y1 = y1 + (maxX - x1) * dy / dx;
+                    x1 = maxX;
+                }
+                else if ((f1 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM
+                        && dy != 0.0) {
+                    x1 = x1 + (maxY - y1) * dx / dy;
+                    y1 = maxY;
+                }
+                else if ((f1 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP
+                        && dy != 0.0) {
+                    x1 = x1 + (minY - y1) * dx / dy;
+                    y1 = minY;
+                }
+                f1 = rect.outcode(x1, y1);
+            }
+            else if (f2 != 0) {
+                // second point is outside, so we update it against one of the
+                // four sides then continue
+                if ((f2 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT
+                        && dx != 0.0) {
+                    y2 = y2 + (minX - x2) * dy / dx;
+                    x2 = minX;
+                }
+                else if ((f2 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT
+                        && dx != 0.0) {
+                    y2 = y2 + (maxX - x2) * dy / dx;
+                    x2 = maxX;
+                }
+                else if ((f2 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM
+                        && dy != 0.0) {
+                    x2 = x2 + (maxY - y2) * dx / dy;
+                    y2 = maxY;
+                }
+                else if ((f2 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP
+                        && dy != 0.0) {
+                    x2 = x2 + (minY - y2) * dx / dy;
+                    y2 = minY;
+                }
+                f2 = rect.outcode(x2, y2);
+            }
+        }
+
+        line.setLine(x1, y1, x2, y2);
+        return true;  // the line is visible - if it wasn't, we'd have
+                      // returned false from within the while loop above
+
+    }
+
 }
\ No newline at end of file