public void AddMpoint(Point point) { foreach (Point mp in MPoints) { if (!mp.Neq(point)) return; } MPoints.Add(point); }
public Trapezoid(Point leftPoint, Point rightPoint, Edge top, Edge bottom) { LeftPoint = leftPoint; RightPoint = rightPoint; Top = top; Bottom = bottom; UpperLeft = null; UpperRight = null; LowerLeft = null; LowerRight = null; Inside = true; Sink = null; }
public Edge(Point p, Point q) { P = p; Q = q; if (q.X - p.X != 0) Slope = (q.Y - p.Y) / (q.X - p.X); else Slope = 0; B = p.Y - (p.X * Slope); Above = null; Below = null; MPoints = new HashSet<Point>(); MPoints.Add(p); MPoints.Add(q); }
// Create an AABB around segments public Trapezoid BoundingBox(List<Edge> edges) { Point max = edges[0].P + _margin; Point min = edges[0].Q - _margin; foreach (Edge e in edges) { if (e.P.X > max.X) max = new Point(e.P.X + _margin, max.Y); if (e.P.Y > max.Y) max = new Point(max.X, e.P.Y + _margin); if (e.Q.X > max.X) max = new Point(e.Q.X + _margin, max.Y); if (e.Q.Y > max.Y) max = new Point(max.X, e.Q.Y + _margin); if (e.P.X < min.X) min = new Point(e.P.X - _margin, min.Y); if (e.P.Y < min.Y) min = new Point(min.X, e.P.Y - _margin); if (e.Q.X < min.X) min = new Point(e.Q.X - _margin, min.Y); if (e.Q.Y < min.Y) min = new Point(min.X, e.Q.Y - _margin); } Edge top = new Edge(new Point(min.X, max.Y), new Point(max.X, max.Y)); Edge bottom = new Edge(new Point(min.X, min.Y), new Point(max.X, min.Y)); Point left = bottom.P; Point right = top.Q; return new Trapezoid(left, right, top, bottom); }
public bool IsBelow(Point point) { return P.Orient2D(Q, point) > 0; }
public bool IsAbove(Point point) { return P.Orient2D(Q, point) < 0; }
// Determines if this point lies inside the trapezoid public bool Contains(Point point) { return (point.X > LeftPoint.X && point.X < RightPoint.X && Top.IsAbove(point) && Bottom.IsBelow(point)); }