Example #1
0
 public override int GetHashCode()
 {
     Debug.Assert(Label != null);
     if (Pt1 != null)
     {
         if (Pt2 != null)
         {
             return(Pt1.GetHashCode() ^ Pt2.GetHashCode() ^ Label.GetHashCode());
         }
         else
         {
             return(Pt1.GetHashCode() ^ Label.GetHashCode());
         }
     }
     else
     {
         if (Pt2 != null)
         {
             return(Pt2.GetHashCode() ^ Label.GetHashCode());
         }
         else
         {
             return(Label.GetHashCode());
         }
     }
 }
        private List <Element> GetRects()
        {
            Pts.Clear();
            _rects.Clear();
            if (Pt1.Equals(Pt2))
            {
                int halfW = PointLineWidth / 2;
                int halfH = PointLineHeight / 2;
                for (int i = 0; i < DispersePointCount; i++)
                {
                    RectangleF rect = new RectangleF(Pt1.X - halfW, Pt1.Y - halfH, PointLineWidth, PointLineHeight);
                    _rects.Add(new RectLineElement(rect)
                    {
                        AutoChangeSize = false, BorderWidth = this.BorderWidth, ForeColor = this.ForeColor
                    });
                }
            }
            else
            {
                A = Pt2.Y - Pt1.Y;
                B = Pt1.X - Pt2.X;
                C = Pt2.X * Pt1.Y - Pt1.X * Pt2.Y;

                float offsetX = (Pt2.X - Pt1.X) / (DispersePointCount - 1);
                float offsetY = (Pt2.Y - Pt1.Y) / (DispersePointCount - 1);

                int halfW = PointLineWidth / 2;
                int halfH = PointLineHeight / 2;

                double aphla = Math.Atan((Pt2.Y - Pt1.Y) / (Pt2.X - Pt1.X));
                int    angle = (int)(aphla / Math.PI * 180);
                if ((Pt2.X - Pt1.X) < 0)
                {
                    angle = angle + 180;
                }
                Debug.WriteLine($"aphla={aphla} angle={angle}");

                for (int i = 0; i < DispersePointCount; i++)
                {
                    float x = Pt1.X + i * offsetX;
                    float y = B == 0 ? Pt1.Y + i * offsetY : -(A * x + C) / B;

                    Pts.Add(new PointF(x, y));

                    RectangleF rect = new RectangleF(x - halfW, y - halfH, PointLineWidth, PointLineHeight);
                    _rects.Add(new RectLineElement(rect, angle)
                    {
                        AutoChangeSize = false, BorderWidth = this.BorderWidth, ForeColor = this.ForeColor
                    });
                }
            }
            return(_rects);
        }
Example #3
0
        //True if same
        public bool IsEqualTo(Quad quad)
        {
            if (quad == null)
            {
                return(false);
            }

            if ((Pt1.IsEqualTo(quad.Pt1) == false) || (Pt2.IsEqualTo(quad.Pt2) == false))
            {
                return(false);
            }
            return(true);
        }
Example #4
0
 //Copy properties from sourceTransform
 public void CopyFrom(Quad sourceQuad)
 {
     if (sourceQuad != null)
     {
         Pt1.CopyFrom(sourceQuad.Pt1);
         Pt2.CopyFrom(sourceQuad.Pt2);
     }
     else
     {
         Pt1 = new Double3();
         Pt2 = new Double3();
     }
 }
Example #5
0
        public float GetDistance(float x, float y)
        {
            float dis = 0f;

            if (Pt1.Equals(Pt2))
            {
                dis = GetLength(x, y, Pt1.X, Pt1.Y);
            }
            else
            {
                float a = Pt2.Y - Pt1.Y;
                float b = Pt1.X - Pt2.X;
                float c = Pt2.X * Pt1.Y - Pt1.X * Pt2.Y;
                dis = (float)(Math.Abs(a * x + b * y + c) / Math.Sqrt(a * a + b * b));
            }
            return(dis);
        }
Example #6
0
 public override bool Equals(Shape other)
 {
     if (other == null)
     {
         return(false);
     }
     if (other is LineSegment)
     {
         var  lineSeg  = other as LineSegment;
         bool equalPt1 = Pt1.Equals(lineSeg.Pt1);
         bool equalPt2 = Pt2.Equals(lineSeg.Pt2);
         if (!(equalPt1 || equalPt2))
         {
             return(false);
         }
     }
     return(base.Equals(other));
 }