svn commit: r16266 - trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/PathItemPlacement.java

Dave Thompson <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: dthompson
Date: 2008-12-06 13:54:09-0800
New Revision: 16266

Modified:
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/PathItemPlacement.java

Log:
Issue 5517: Improved paint of pathitem line.

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/PathItemPlacement.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/PathItemPlacement.java?view=diff&pathrev=16266&r1=16265&r2=16266
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/PathItemPlacement.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/PathItemPlacement.java	2008-12-06 13:54:09-0800
@@ -606,8 +606,6 @@
      * Finds the intersection point between the border of a Rectangle r and 
      * a line drawn between two Points pOut (outside the rectangle) and pIn 
      * (inside the rectangle).
-     * Actually, we just do a cheat and find the midpoint of the edge which
-     * the the line crosses.
      * If the pIn is not inside the rectangle, or if any other problem occurs,
      * pIn is returned. 
      * @param r Rectangle to find the intersection of.
@@ -620,24 +618,46 @@
         m = new Line2D.Double(pOut, pIn);
         n = new Line2D.Double(r.x, r.y, r.x + r.width, r.y);
         if (m.intersectsLine(n)) {
-            return new Point(r.x + r.width / 2, r.y);
+            return intersection(m, n);
         }
         n = new Line2D.Double(r.x + r.width, r.y, r.x + r.width, 
                 r.y + r.height);
         if (m.intersectsLine(n)) {
-            return new Point(r.x + r.width, r.y + r.height / 2);
+            return intersection(m, n);
         }
         n = new Line2D.Double(r.x, r.y + r.height, r.x + r.width, 
                 r.y + r.height);
         if (m.intersectsLine(n)) {
-            return new Point(r.x + r.width / 2, r.y + r.height);
+            return intersection(m, n);
         }
         n = new Line2D.Double(r.x, r.y, r.x, r.y + r.width);
         if (m.intersectsLine(n)) {
-            return new Point(r.x, r.y + r.height / 2);
+            return intersection(m, n);
         }
         // Should never get here.  If we do, return the inner point.
         LOG.warn("Could not find rectangle intersection, using inner point.");
         return pIn;
     }
+    
+    /**
+     * Finds the intersection point of two lines.
+     * It is surprising that this method isn't already available in the base 
+     * Line2D class of Java.  If a stock method exists or is implemented in
+     * future, feel free replace this code with it.
+     * @param m First line.
+     * @param n Second line.
+     * @return Intersection point of first and second line.
+     */
+    private Point intersection(Line2D m, Line2D n) {
+        double d = (n.getY2() - n.getY1()) * (m.getX2() - m.getX1()) 
+                - (n.getX2() - n.getX1()) * (m.getY2() - m.getY1());
+        double a = (n.getX2() - n.getX1()) * (m.getY1() - n.getY1()) 
+                - (n.getY2() - n.getY1()) * (m.getX1() - n.getX1());
+        
+        double as = a / d;
+        
+        double x = m.getX1() + as * (m.getX2() - m.getX1());
+        double y = m.getY1() + as * (m.getY2() - m.getY1());
+        return new Point((int) x, (int) y);
+    }
 }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=980616

To unsubscribe from this discussion, e-mail: [[email protected]].
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.