Exemplo n.º 1
0
 DPoint CalcSizeDelta(DPoint pt, Figure f, bool lockAspectRatio)
 {
     if (lockAspectRatio && f.Width > 0)
     {
         pt = pt.Offset(-dragPt.X, -dragPt.Y);
         double m = f.Height / f.Width;
         DPoint intersectionPt = DGeom.IntersectionOfTwoLines(m, f.BottomRight, -1, pt);
         // using soh/cah/toa
         double h = DGeom.DistBetweenTwoPts(f.BottomRight, intersectionPt);
         double A = Math.Atan(m);
         // cos(A) = a/h
         double dX = Math.Cos(A) * h;
         // sin(A) = o/h
         double dY = Math.Sin(A) * h;
         // find out the angle of the line between the mouse pt and the botton left of the figure
         double angle = -(Math.Atan2(pt.Y - f.BottomRight.Y, pt.X - f.BottomRight.X) - Math.PI);
         // if the angle is on the topleft side (225 deg to 45 deg) then we are resizing smaller
         if (angle < Math.PI / 4 || angle > Math.PI + Math.PI / 4)
             return new DPoint(-dX, -dY);
         else
             return new DPoint(dX, dY);
     }
     else
         return new DPoint((pt.X - f.X) - f.Width - dragPt.X, (pt.Y - f.Y) - f.Height - dragPt.Y);
 }
Exemplo n.º 2
0
 public DPoint EngineToClient(DPoint pt)
 {
     pt = new DPoint(pt.X * scale, pt.Y * scale);
     return pt.Offset(-HortScroll + OffsetX, -VertScroll + OffsetY);
 }
Exemplo n.º 3
0
 public static DPoint RotatePoint(DPoint pt, DPoint origin, double angle)
 {
     if (angle == 0 || (pt.X == origin.X && pt.Y == origin.Y))
         return new DPoint(pt.X, pt.Y);
     // set to origin
     pt = pt.Offset(-origin.X, -origin.Y);
     // rotate point
     DPoint rotatedPt = new DPoint(pt.X * Math.Cos(angle) - pt.Y * Math.Sin(angle),
                                   pt.X * Math.Sin(angle) + pt.Y * Math.Cos(angle));
     // unset from origin
     rotatedPt = rotatedPt.Offset(origin.X, origin.Y);
     return rotatedPt;
 }