コード例 #1
0
 private void DrawLineWithIntCords(Graphics g)
 {
     if (is_drawing)
     {
         is_drawing = false;
         LineWithIntCords.Draw(g, p_begin, p_end);
     }
 }
コード例 #2
0
        public static void DrawRect(Graphics g, Rectangle r)
        {
            LineWithIntCords.Draw(g, new Point(r.X, 0), new Point(r.X, 1000));

            LineWithIntCords.Draw(g, new Point(r.X + r.Width, 0), new Point(r.X + r.Width, 1000));

            LineWithIntCords.Draw(g, new Point(0, r.Y), new Point(1000, r.Y));

            LineWithIntCords.Draw(g, new Point(0, r.Y + r.Height), new Point(1000, r.Y + r.Height));
        }
コード例 #3
0
        public void DrawCirusBec(Graphics g, Segment seg)
        {
            var dir   = seg.Direction;
            var tA    = 0.0f;
            var tB    = 1.0f;
            var edges = GetEdges();

            foreach (var edge in edges)
            {
                switch (Math.Sign(edge.Normal.ScalarMul(dir)))
                {
                case -1:
                {
                    var t = seg.IntersectionParameter(edge);
                    if (t > tA)
                    {
                        tA = t;
                    }
                    break;
                }

                case +1:
                {
                    var t = seg.IntersectionParameter(edge);
                    if (t < tB)
                    {
                        tB = t;
                    }
                    break;
                }

                case 0:
                {
                    if (!edge.OnLeft(seg.A))
                    {
                        return;
                    }
                    break;
                }
                }
            }
            if (tA > tB)
            {
                return;
            }
            seg = seg.Morph(tA, tB);

            LineWithIntCords.Draw(g, new Point((int)Math.Round(seg.A.X), (int)Math.Round(seg.A.Y)), new Point((int)Math.Round(seg.B.X), (int)Math.Round(seg.B.Y)));
        }
コード例 #4
0
        public static void SredTochki(Graphics g, Rectangle r, Point p1, Point p2)
        {
            if (Math.Abs(p1.X - p2.X) <= 1 && Math.Abs(p1.Y - p2.Y) <= 1)
            {
                return;
            }
            if (isInside(r, p1) && isInside(r, p2))
            {
                LineWithIntCords.Draw(g, p1, p2);
            }

            int code1 = GetCode(r, p1);
            int code2 = GetCode(r, p2);

            if ((code1 & code2) != 0)
            {
                return;
            }

            SredTochki(g, r, p1, new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2));
            SredTochki(g, r, new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2), p2);
        }
コード例 #5
0
        public static void SazerlendCoen(Graphics g, Rectangle r, Point p1, Point p2)
        {
            int   code, code1, code2;
            Point p;

            code1 = GetCode(r, p1);
            code2 = GetCode(r, p2);

            while (code1 != 0 || code2 != 0)
            {
                if ((code1 & code2) != 0)
                {
                    return;
                }

                if (code1 != 0)
                {
                    code = code1;
                    p    = p1;
                }
                else
                {
                    code = code2;
                    p    = p2;
                }

                if ((code & LEFT) != 0)
                {
                    p.Y += (p1.Y - p2.Y) * (r.X - p.X) / (p1.X - p2.X);
                    p.X  = r.X;
                }
                else if ((code & RIGHT) != 0)
                {
                    p.Y += (p1.Y - p2.Y) * (r.X + r.Width - p.X) / (p1.X - p2.X);
                    p.X  = r.X + r.Width;
                }
                else if ((code & BOT) != 0)
                {
                    p.X += (p1.X - p2.X) * (r.Y + r.Height - p.Y) / (p1.Y - p2.Y);
                    p.Y  = r.Y + r.Height;
                }
                else if ((code & TOP) != 0)
                {
                    p.X += (p1.X - p2.X) * (r.Y - p.Y) / (p1.Y - p2.Y);
                    p.Y  = r.Y;
                }

                if (code == code1)
                {
                    p1    = p;
                    code1 = GetCode(r, p1);
                }
                else
                {
                    p2    = p;
                    code2 = GetCode(r, p2);
                }
            }


            LineWithIntCords.Draw(g, p1, p2);
        }