public static int PointOnWhichSideOfLineSegment(Point linePoint1, Point linePoint2, Point point)
        {
            Point lineVec  = PointUtil.Minus(linePoint2, linePoint1);
            Point pointVec = PointUtil.Minus(point, linePoint1);

            float dot = PointUtil.Dot(pointVec, lineVec);

            //point is on side of linePoint2, compared to linePoint1
            if (dot > 0)
            {
                //point is on the line segment
                if (PointUtil.Magnitude(pointVec) <= PointUtil.Magnitude(lineVec))
                {
                    return(0);
                }

                //point is not on the line segment and it is on the side of linePoint2
                else
                {
                    return(2);
                }
            }

            //Point is not on side of linePoint2, compared to linePoint1.
            //Point is not on the line segment and it is on the side of linePoint1.
            else
            {
                return(1);
            }
        }
        public static Point ProjectPointOnLineSegment(Point linePoint1, Point linePoint2, Point point)
        {
            Point vector = PointUtil.Minus(linePoint2, linePoint1);

            Point projectedPoint = ProjectPointOnLine(linePoint1, PointUtil.Normalize(vector), point);

            int side = PointOnWhichSideOfLineSegment(linePoint1, linePoint2, projectedPoint);

            //The projected point is on the line segment
            if (side == 0)
            {
                return(projectedPoint);
            }

            if (side == 1)
            {
                return(linePoint1);
            }

            if (side == 2)
            {
                return(linePoint2);
            }

            //output is invalid
            return(Point.Empty);
        }
        public void GenBlock()
        {
            ClearBlock();
            Document a = canvas1.GetCurrent();

            a.GetLinesOfRoom();
            foreach (Line line in a.lines)
            {
                UCWall temp = new UCWall();
                canvas1.Controls.Add(temp);
                Size tSize = new Size(PointUtil.Minus(line.pB, line.pA));
                if (tSize.Width == 0)
                {
                    temp.isVertical = true;
                    temp.Location   = PointUtil.Plus(line.pA, new Point(-2, 2));
                    tSize.Width     = 5;
                    tSize.Height   -= 2;
                }
                else
                {
                    temp.isVertical = false;
                    temp.Location   = PointUtil.Plus(line.pA, new Point(2, -2));
                    tSize.Height    = 5;
                    tSize.Width    -= 2;
                }
                temp.Size = tSize;
                canvas1.Controls.SetChildIndex(temp, 0);

                //Console.WriteLine("draw loc :" + temp.Location + "size : " + temp.Size);
            }
        }
        public static Point ProjectPointOnLine(Point linePoint, Point lineVec, Point point)
        {
            //get vector from point on line to point in space
            Point linePointToPoint = PointUtil.Minus(point, linePoint);

            int t = PointUtil.Dot(linePointToPoint, lineVec);

            return(PointUtil.Plus(linePoint, new Point(lineVec.X * t, lineVec.Y * t)));
        }
 public Door(Point a, int idx, bool _isDoor)
 {
     pA   = a;
     kind = idx;
     if (kind % 2 == 0)
     {
         pB = PointUtil.Plus(pA, new Point(0, 50));
     }
     else
     {
         pB = PointUtil.Plus(pA, new Point(50, 0));
     }
     isDoor = _isDoor;
 }