Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3175


Ignore:
Timestamp:
03/22/10 15:48:39 (15 years ago)
Author:
mkommend
Message:

corrected bug in connection hit test (ticket #867)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Diagram elements/Connections/Connection.cs

    r3174 r3175  
    193193      r1.Inflate(3, 3);
    194194      r2.Inflate(3, 3);
    195       //this is like a topological neighborhood
    196       //the connection is shifted left and right
    197       //and the point under consideration has to be in between.           
    198195      if (RectangleF.Union(r1, r2).Contains(p))
    199196      {
    200         //if (p1.Y < p2.Y) //SWNE
    201         //{
    202         //  o = r1.Left + (((r2.Left - r1.Left) * (p.Y - r1.Bottom)) / (r2.Bottom - r1.Bottom));
    203         //  u = r1.Right + (((r2.Right - r1.Right) * (p.Y - r1.Top)) / (r2.Top - r1.Top));
    204         //  return ((p.X > o) && (p.X < u));
    205         //} else //NWSE
    206         //{
    207         //  o = r1.Left + (((r2.Left - r1.Left) * (p.Y - r1.Top)) / (r2.Top - r1.Top));
    208         //  u = r1.Right + (((r2.Right - r1.Right) * (p.Y - r1.Bottom)) / (r2.Bottom - r1.Bottom));
    209         //  return ((p.X > o) && (p.X < u));
    210         //}
    211         return true;
     197        PointF connectionVector = new PointF(p2.X - p1.X, p2.Y - p1.Y);
     198        PointF normalVector = new PointF(connectionVector.Y, connectionVector.X * -1);
     199        PointF pointVector = new PointF(p.X - p1.X, p.Y - p1.Y);
     200
     201        double normalVectorLength = Math.Sqrt(normalVector.X * normalVector.X + normalVector.Y * normalVector.Y);
     202        double distance = Math.Abs(pointVector.X * normalVector.X + pointVector.Y * normalVector.Y) / normalVectorLength;
     203
     204        return distance < 5;
    212205      }
    213206      return false;
Note: See TracChangeset for help on using the changeset viewer.