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); }
public override bool HitTest(RealPoint pt, CoordinateSystem cs) { if (cs.GetDistance(pt.x, pt.y, x, y) < cs.epsilon) { return(true); } return(false); }
public override bool HitTest(RealPoint pt, CoordinateSystem cs) { if (cs.GetDistance(pt, centre) < radius) { return(true); } return(false); }
public RealCircle(RealPoint point1, RealPoint point2, CoordinateSystem cs) { this.centre = point1; circumference = point2; x = centre.x; y = centre.y; radius = cs.GetDistance(centre, circumference); }
public override bool HitTest(RealPoint pt, CoordinateSystem cs) { // 4 < 6 8 > 4 8 6 2 < 4 if (firstPoint.x < pt.x && firstPoint.y > pt.y && secondPoint.x > pt.x && secondPoint.y < pt.y) { return(true); } return(false); }
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.radius) { 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; } }
public bool HitTestLabel(RealPoint clickPoint) { if (x + label.offsetX < clickPoint.x && y + label.offsetY > clickPoint.y && x + label.offsetX + label.width > clickPoint.x && y + label.offsetY - label.height < clickPoint.y) { return(true); } return(false); }
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); }
private RealFigure SelectFigure(MouseEventArgs e) { foreach (RealFigure figure in realFigureList) { double mouseX = cs1.VisualToRealX(e.X); double mouseY = cs1.VisualToRealY(e.Y); clickPoint = new RealPoint(mouseX, mouseY); if (figure.HitTest(clickPoint, cs1)) { return(figure); } } return(null); }
private void SelectLabel(MouseEventArgs e) // top left --> center // change this code { foreach (RealFigure figure in realFigureList) { if (figure is RealPoint) { RealPoint point = (RealPoint)figure; double mouseX = cs1.VisualToRealX(e.X); double mouseY = cs1.VisualToRealY(e.Y); clickPoint = new RealPoint(mouseX, mouseY); if (point.HitTestLabel(clickPoint)) { selectedLabel = point.label; } } } }
public Form1() { InitializeComponent(); // create Coordinate System int unitInterval = 30; int x0 = pictureBox1.Width / 2; int y0 = pictureBox1.Height / 2; 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 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); }
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); }
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; } }
public RealRectangle(RealPoint first, RealPoint second) { this.firstPoint = first; this.secondPoint = second; }
public RealSegment(RealPoint first, RealPoint second) { this.firstPoint = first; this.secondPoint = second; }
public double GetDistance(RealPoint p1, RealPoint p2) { return(GetDistance(p1.x, p1.y, p2.x, p2.y)); }
public RealIntersect(RealSegment ab, RealSegment cd) { this.ab = ab; this.cd = cd; intersectPoint = new RealPoint(0, 0); }
public virtual bool HitTest(RealPoint pt, CoordinateSystem cs) { return(false); }
public RealIsoscelesTriangle(RealPoint first, RealPoint second) { this.firstPoint = first; this.secondPoint = second; }