private void WHRect(out fpoint a, out fpoint b) { fpoint uppoint; fpoint dwpoint; if (Up.y < Down.y) { uppoint = Up; dwpoint = Down; } else { uppoint = Down; dwpoint = Up; } if (uppoint.x > dwpoint.x) { double temp = dwpoint.y; dwpoint.y = uppoint.y; uppoint.y = temp; fpoint tmp = dwpoint; dwpoint = uppoint; uppoint = tmp; } a = uppoint; b = dwpoint; }
//переводит истинны координаты в экранные public Point RealToScreen(fpoint pt) { try { return(new Point(Convert.ToInt32(pt.x * rs_dx), Convert.ToInt32(pt.y * rs_dy))); } catch (Exception e) { onException("Ошибка при преобразовании координаты", e.Message); return(new Point()); } }
public override double GetR(fpoint f) { fpoint a; fpoint b; WHRect(out a, out b); if ((f.x > a.x) && (f.y > a.y) && (f.x < b.x) && (f.y < b.y)) { return(10); } return(-1); }
//Получает ближайшую фигуру к указанной экранной точке public int GetNearShape(Point pt) { fpoint fpt = ScreenToReal(pt); double minval = double.MaxValue; double val = 0; int minsp = -1; for (int i = 0; i < shapelist.Count; i++) { val = shapelist[i].GetR(fpt); if ((val < minval) && (val != -1)) { minval = val; minsp = i; } } return(minsp); }
public override double GetR(fpoint f) { fpoint bp; fpoint cp; if (fpoint.GetRasst(f, fpEnd) > fpoint.GetRasst(f, fpBeg)) { bp = fpEnd - fpBeg; cp = f - fpBeg; } else { bp = fpBeg - fpEnd; cp = f - fpEnd; } double a = fpoint.GetRasstNormalized(cp); double b = fpoint.GetRasstNormalized(bp); double cosa = (bp.x * cp.x + bp.y * cp.y) / (a * b); double res = cosa >= 0 ? Math.Sqrt(1 - cosa * cosa) * a : -1; return(res < 50 ? res : -1); }
//Получает расстояние от данной точки до фигуры public abstract double GetR(fpoint f);
public sRect(DelegateContainer _dlc, double x1, double y1, double x2, double y2) : base(_dlc) { this.Up = new fpoint(x1, y1); this.Down = new fpoint(x2, y2); }
public sRect(DelegateContainer _dlc, Point Down, Point Up) : base(_dlc) { this.Up = base.dlc.fScreenToReal(Down); this.Down = base.dlc.fScreenToReal(Up); }
public override double GetR(fpoint f) { double val = fpoint.GetRasst(Center, f); return(val < Radius ? val : -1); }
public sCircle(DelegateContainer _dlc, double x1, double y1, double r) : base(_dlc) { this.Center = new fpoint(x1, y1); this.Radius = r; }
public sCircle(DelegateContainer _dlc, Point Down, Point Up) : base(_dlc) { this.Center = base.dlc.fScreenToReal(Down); this.Radius = fpoint.GetRasst(base.dlc.fScreenToReal(Down), base.dlc.fScreenToReal(Up)); }
public sLine(DelegateContainer _dlc, double x1, double y1, double x2, double y2) : base(_dlc) { fpBeg = new fpoint(x1, y1); fpEnd = new fpoint(x2, y2); }
public sLine(DelegateContainer _dlc, Point p1, Point p2) : base(_dlc) { fpBeg = base.dlc.fScreenToReal(p1); fpEnd = base.dlc.fScreenToReal(p2); }
public override double GetR(fpoint f) { double val = fpoint.GetRasst(this.Center, f); return(val < 50 ? val: -1); }
public sCross(DelegateContainer _dlc, double x, double y) : base(_dlc) { Center = new fpoint(x, y); }
public sCross(DelegateContainer _dlc, int x, int y) : base(_dlc) { Center = base.dlc.fScreenToReal(new Point(x, y)); }