Beispiel #1
0
        public override bool HitTest(RealPoint pt, CoordinateSystem cs)
        {
            double x1 = firstPoint.x;
            double y1 = firstPoint.y;
            double x2 = secondPoint.x;
            double y2 = secondPoint.y;

            double x3 = secondPoint.x;
            double y3 = firstPoint.y;
            if (firstPoint.y > secondPoint.y)
            {
                x3 = firstPoint.x;
                y3 = secondPoint.y;
            }
          

            double x0 = pt.x;
            double y0 = pt.y;
            double a = (x1 - x0) * (y2 - y1) - (x2 - x1) * (y1 - y0);
            double b = (x2 - x0) * (y3 - y2) - (x3 - x2) * (y2 - y0);
            double c = (x3 - x0) * (y1 - y3) - (x1 - x3) * (y3 - y0);



            if ((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0))
            {
                return true;
            }

            return false;
        }
Beispiel #2
0
        private void AddIntersectAction(object sender, MouseEventArgs e)
        {
            if (selectedSeg1 == null)
            {
                double mouseX = cs1.VisualToRealX(e.X);
                double mouseY = cs1.VisualToRealY(e.Y);
                clickPoint = new RealPoint(mouseX, mouseY);

                selectedSeg1 = (RealSegment)SelectFigure(clickPoint);
                if (selectedSeg1 != null)
                {
                    selectedSeg1.SetBackLight();
                }
                this.Text = "select first segment";
            }

            else
            {
                double mouseX = cs1.VisualToRealX(e.X);
                double mouseY = cs1.VisualToRealY(e.Y);
                clickPoint = new RealPoint(mouseX, mouseY);

                this.Text    = "select second segment";
                selectedSeg2 = (RealSegment)SelectFigure(clickPoint);
                if (selectedSeg2 != null)
                {
                    selectedSeg1.UnSetBackLight();
                    RealIntersect intersectPoint = new RealIntersect(selectedSeg1, selectedSeg2);
                    realFigureList.Add(intersectPoint);
                    selectedSeg1 = null;
                    selectedSeg2 = null;
                }
            }
        }
Beispiel #3
0
 public override bool HitTest(RealPoint pt, CoordinateSystem cs)
 {
     if (cs.GetDistance(pt.x, pt.y, intersectPoint.x, intersectPoint.y) < cs.radiusPoint)
     {
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 public override bool HitTest(RealPoint pt, CoordinateSystem cs)
 {
     if (cs.RealToVisualDistance(cs.GetDistance(pt.x, pt.y, x, y)) < cs.radiusPoint) // при масштабирование изменять радиус захвата точки
     {
         return(true);
     }
     return(false);
 }
Beispiel #5
0
 public RealCircle(RealPoint point1, RealPoint point2, CoordinateSystem cs)
 {
     this.centre   = point1;
     circumference = point2;
     x             = centre.x;
     y             = centre.y;
     radius        = cs.GetDistance(centre, circumference);
 }
Beispiel #6
0
 public override bool HitTest(RealPoint pt, CoordinateSystem cs)
 {
     if (cs.GetDistance(pt, centre) < radius)
     {
         return(true);
     }
     return(false);
 }
Beispiel #7
0
 public override bool HitTest(RealPoint pt, CoordinateSystem cs)
 {
     if (firstPoint.x < pt.x && pt.x < secondPoint.x && firstPoint.y > pt.y && pt.y > secondPoint.y ||
         secondPoint.x < pt.x && pt.x < firstPoint.x && secondPoint.y > pt.y && pt.y > firstPoint.y ||
         firstPoint.x > pt.x && pt.x > secondPoint.x && firstPoint.y > pt.y && pt.y > secondPoint.y ||
         secondPoint.x > pt.x && pt.x > firstPoint.x && secondPoint.y > pt.y && pt.y > firstPoint.y)
     {
         return(true);
     }
     return(false);
 }
Beispiel #8
0
 private RealFigure SelectFigure(RealPoint clickPoint)
 {
     foreach (RealFigure figure in realFigureList)
     {
         if (figure.HitTest(clickPoint, cs1))
         {
             return(figure);
         }
     }
     return(null);
 }
Beispiel #9
0
        private void AddPolygonAction(object sender, MouseEventArgs e)
        {
            double x;
            double y;

            if (RoundingButton.Checked)
            {
                x = Math.Round(cs1.VisualToRealX(e.X));
                y = Math.Round(cs1.VisualToRealY(e.Y));
            }
            else
            {
                x = cs1.VisualToRealX(e.X);
                y = cs1.VisualToRealY(e.Y);
            }

            if (creatingLine)
            {
                if (RoundingButton.Checked)
                {
                    selectedPoint.x = Math.Round(selectedPoint.x);
                    selectedPoint.y = Math.Round(selectedPoint.y);
                }
                selectedPoint = new RealPoint(x, y);
                int x1 = cs1.RealToVisualX(pointList[0].x);
                int y1 = cs1.RealToVisualY(pointList[0].y);
                if (cs1.GetDistance(x1, y1, e.X, e.Y) < cs1.radiusPoint)
                {
                    creatingLine = false;
                    pointList.RemoveAt(pointList.Count - 1);
                    realFigureList.RemoveAt(realFigureList.Count - 1);
                }
                else
                {
                    pointList.Add(selectedPoint);
                    realFigureList.Add(selectedPoint);
                }
            }
            else
            {
                pointList   = new List <RealPoint>();
                firstPoint  = new RealPoint(x, y);
                secondPoint = new RealPoint(x, y);
                realFigureList.Add(firstPoint);
                realFigureList.Add(secondPoint);
                pointList.Add(firstPoint);
                pointList.Add(secondPoint);

                RealPolygon polygon = new RealPolygon(pointList);
                realFigureList.Add(polygon);
                selectedPoint = secondPoint;
                creatingLine  = true;
            }
        }
Beispiel #10
0
 private Label SelectLabel(MouseEventArgs e) // top left --> center // change this code
 {
     foreach (RealFigure figure in realFigureList)
     {
         if (figure is RealPoint)
         {
             RealPoint point = (RealPoint)figure;
             clickPointPixel.X = e.X;
             clickPointPixel.Y = e.Y;
             if (point.HitTestLabel(clickPointPixel, cs1))
             {
                 return(point.label);
             }
         }
     }
     return(null);
 }
Beispiel #11
0
        private void MiddlePointAction(object sender, MouseEventArgs e)
        {
            double mouseX = cs1.VisualToRealX(e.X);
            double mouseY = cs1.VisualToRealY(e.Y);

            clickPoint   = new RealPoint(mouseX, mouseY);
            selectedSeg1 = SelectFigure(clickPoint) as RealSegment;
            if (selectedSeg1 != null)
            {
                selectedSeg1.SetBackLight();
                RealPoint middlePoint = new RealPoint(
                    (selectedSeg1.firstPoint.x + selectedSeg1.secondPoint.x) / 2,
                    (selectedSeg1.firstPoint.y + selectedSeg1.secondPoint.y) / 2);
                realFigureList.Add(middlePoint);
            }
            this.Text = "MiddlePointAction select first segment";
        }
Beispiel #12
0
        public override bool HitTest(RealPoint pt, CoordinateSystem cs)
        {
            double x    = pt.x;
            double y    = pt.y;
            int    npol = vertices.Count;
            int    j    = npol - 1;
            bool   c    = false;

            for (int i = 0; i < npol; i++)
            {
                if ((((vertices[i].y <= y) && (y < vertices[j].y)) || ((vertices[j].y <= y) && (y < vertices[i].y))) &&
                    (x > (vertices[j].x - vertices[i].x) * (y - vertices[i].y) / (vertices[j].y - vertices[i].y) + vertices[i].x))
                {
                    c = !c;
                }
                j = i;
            }
            return(c);
        }
Beispiel #13
0
        public override bool HitTest(RealPoint pt, CoordinateSystem cs)
        {
            double x0 = pt.x;
            double y0 = pt.y;

            double x1 = firstPoint.x;
            double y1 = firstPoint.y;

            double x2 = secondPoint.x;
            double y2 = secondPoint.y;


            if (Math.Abs((x2 - x0) / (x2 - x1) - (y2 - y0) / (y2 - y1)) < 0.1 &&
                (x1 - x0) * (x2 - x0) < 0 && (y1 - y0) * (y2 - y0) < 0
                )
            {
                return(true);
            }
            return(false);
        }
Beispiel #14
0
        private void AddIsoscelesAction(object sender, MouseEventArgs e)
        {
            double x;
            double y;

            if (RoundingButton.Checked)
            {
                x = Math.Round(cs1.VisualToRealX(e.X));
                y = Math.Round(cs1.VisualToRealY(e.Y));
            }
            else
            {
                x = cs1.VisualToRealX(e.X);
                y = cs1.VisualToRealY(e.Y);
            }

            if (creatingLine)
            {
                if (RoundingButton.Checked)
                {
                    selectedPoint.x = Math.Round(selectedPoint.x);
                    selectedPoint.y = Math.Round(selectedPoint.y);
                }
                selectedPoint = null;
                creatingLine  = false;
            }
            else
            {
                firstPoint = new RealPoint(x, y);
                realFigureList.Add(firstPoint);
                secondPoint = new RealPoint(x, y);
                realFigureList.Add(secondPoint);
                RealIsoscelesTriangle rt = new RealIsoscelesTriangle(firstPoint, secondPoint);
                realFigureList.Add(rt);
                selectedPoint = secondPoint;
                creatingLine  = true;
            }
        }
Beispiel #15
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (MoveButton.Checked)
            {
                selectedLabel = SelectLabel(e);
                double mouseX = cs1.VisualToRealX(e.X);
                double mouseY = cs1.VisualToRealY(e.Y);
                clickPoint = new RealPoint(mouseX, mouseY);
                selected   = SelectFigure(clickPoint);
                if (selected != null)
                {
                    selected.SetBackLight();
                }
                else if (selectedLabel != null)
                {
                    // selectedLabel.SetBackLight(); TODO
                }
                else
                {
                    csMove            = true;
                    clickPointPixel.X = e.X;
                    clickPointPixel.Y = e.Y;
                }
                pictureBox1.Invalidate();
            }

            if (DeleteButton.Checked)
            {
                double mouseX = cs1.VisualToRealX(e.X);
                double mouseY = cs1.VisualToRealY(e.Y);
                clickPoint = new RealPoint(mouseX, mouseY);

                selected = SelectFigure(clickPoint);
                realFigureList.Remove(selected);
                selected = null;
                pictureBox1.Invalidate();
            }
        }
Beispiel #16
0
        public Form1()
        {
            InitializeComponent();
            this.pictureBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseWheel);
            // create Coordinate System
            double unitInterval = 1024;
            int    x0           = 100;
            int    y0           = 200;

            marginWidth        = 25;
            marginHeight       = 70;
            pictureBox1.Width  = this.Width - marginWidth;
            pictureBox1.Height = this.Height - marginHeight;
            int w = pictureBox1.Width;
            int h = pictureBox1.Height;

            cs1            = new CoordinateSystem(unitInterval, x0, y0, w, h);
            firstPoint     = null;
            secondPoint    = null;
            creatingLine   = false;
            realFigureList = new List <RealFigure>();
            selectedPoint  = null;
            selectedLabel  = null;
        }
 public RealIsoscelesTriangle(RealPoint first, RealPoint second)
 {
     this.firstPoint  = first;
     this.secondPoint = second;
 }
Beispiel #18
0
 public RealRightTriangle(RealPoint first, RealPoint second)
 {
     this.firstPoint = first;
     this.secondPoint = second;
 }
Beispiel #19
0
 public RealSegment(RealPoint first, RealPoint second)
 {
     this.firstPoint  = first;
     this.secondPoint = second;
 }
Beispiel #20
0
 public virtual bool HitTest(RealPoint pt, CoordinateSystem cs)
 {
     return(false);
 }
Beispiel #21
0
 public double GetDistance(RealPoint p1, RealPoint p2)
 {
     return(GetDistance(p1.x, p1.y, p2.x, p2.y));
 }
Beispiel #22
0
 public RealIntersect(RealSegment ab, RealSegment cd)
 {
     this.ab        = ab;
     this.cd        = cd;
     intersectPoint = new RealPoint(0, 0);
 }