/// <inheritdoc /> public Rectangle Bounds() { var bounds = new Rectangle(); bounds.Expand(this.points); return(bounds); }
/// <inheritdoc /> public Rectangle Bounds() { var bounds = new Rectangle(); bounds.Expand(this.points as IEnumerable <Point>); return(bounds); }
/// <inheritdoc /> public Rectangle Bounds() { var bounds = new Rectangle(); bounds.Expand(this.points.ConvertAll(v => new Point(v.x, v.y, v.label))); return(bounds); }
public StandardVoronoi(Mesh mesh, Rectangle box, IVoronoiFactory factory, IPredicates predicates) : base(mesh, factory, predicates, true) { // We assume the box to be at least as large as the mesh. box.Expand(mesh.bounds); // We explicitly told the base constructor to call the Generate method, so // at this point the basic Voronoi diagram is already created. PostProcess(box); }
/// <summary> /// Returns the bounding box of the triangle. /// </summary> /// <param name="triangle">Triangle instance.</param> /// <returns></returns> public static Rectangle Bounds(this ITriangle triangle) { var bounds = new Rectangle(); for (int i = 0; i < 3; i++) { bounds.Expand(triangle.GetVertex(i)); } return(bounds); }
/// <inheritdoc /> public Rectangle Bounds() { // NOTE: ported for unity List <Point> points = this.points.ConvertAll(x => (Point)x); var bounds = new Rectangle(); bounds.Expand(points); return(bounds); }
private static Point FindPointInPolygon(List <Vertex> contour, int limit, double eps) { var bounds = new Rectangle(); bounds.Expand(contour.ConvertAll(v => new Point(v.x, v.y, v.label))); int length = contour.Count; var test = new Point(); Point a, b, c; // Current corner points. double bx, by; double dx, dy; double h; var predicates = new RobustPredicates(); a = contour[0]; b = contour[1]; for (int i = 0; i < length; i++) { c = contour[(i + 2) % length]; // Corner point. bx = b.x; by = b.y; // NOTE: if we knew the contour points were in counterclockwise order, we // could skip concave corners and search only in one direction. h = predicates.CounterClockwise(a, b, c); if (Math.Abs(h) < eps) { // Points are nearly co-linear. Use perpendicular direction. dx = (c.y - a.y) / 2; dy = (a.x - c.x) / 2; } else { // Direction [midpoint(a-c) -> corner point] dx = (a.x + c.x) / 2 - bx; dy = (a.y + c.y) / 2 - by; } // Move around the contour. a = b; b = c; h = 1.0; for (int j = 0; j < limit; j++) { // Search in direction. test.x = bx + dx * h; test.y = by + dy * h; if (bounds.Contains(test) && IsPointInPolygon(test, contour)) { return(test); } // Search in opposite direction (see NOTE above). test.x = bx - dx * h; test.y = by - dy * h; if (bounds.Contains(test) && IsPointInPolygon(test, contour)) { return(test); } h = h / 2; } } throw new Exception(); }
private static Point FindPointInPolygon(List<Vertex> contour) { var bounds = new Rectangle(); bounds.Expand(contour); int length = contour.Count; int limit = 8; var test = new Point(); Point a, b; // Current edge. double cx, cy; // Center of current edge. double dx, dy; // Direction perpendicular to edge. for (int i = 0; i < length; i++) { a = contour[i]; b = contour[(i + 1) % length]; cx = (a.x + b.x) / 2; cy = (a.y + b.y) / 2; dx = (b.y - a.y) / 1.374; dy = (a.x - b.x) / 1.374; for (int j = 1; j <= limit; j++) { // Search to the right of the segment. test.x = cx + dx / j; test.y = cy + dy / j; if (bounds.Contains(test) && IsPointInPolygon(test, contour)) { return test; } // Search on the other side of the segment. test.x = cx - dx / j; test.y = cy - dy / j; if (bounds.Contains(test) && IsPointInPolygon(test, contour)) { return test; } } } throw new Exception(); }
public static Rectangle Bounds(this ITriangle triangle) { var bounds = new Rectangle(); for (int i = 0; i < 3; i++) { bounds.Expand(triangle.GetVertex(i)); } return bounds; }
/// <inheritdoc /> public Rectangle Bounds() { var bounds = new Rectangle(); bounds.Expand(this.points.ToPoints()); return bounds; }
private static Point FindPointInPolygon(List<Vertex> contour, int limit, double eps) { var bounds = new Rectangle(); bounds.Expand(contour.ToPoints()); int length = contour.Count; var test = new Point(); Point a, b, c; // Current corner points. double bx, by; double dx, dy; double h; var predicates = new RobustPredicates(); a = contour[0]; b = contour[1]; for (int i = 0; i < length; i++) { c = contour[(i + 2) % length]; // Corner point. bx = b.x; by = b.y; // NOTE: if we knew the contour points were in counterclockwise order, we // could skip concave corners and search only in one direction. h = predicates.CounterClockwise(a, b, c); if (Math.Abs(h) < eps) { // Points are nearly co-linear. Use perpendicular direction. dx = (c.y - a.y) / 2; dy = (a.x - c.x) / 2; } else { // Direction [midpoint(a-c) -> corner point] dx = (a.x + c.x) / 2 - bx; dy = (a.y + c.y) / 2 - by; } // Move around the contour. a = b; b = c; h = 1.0; for (int j = 0; j < limit; j++) { // Search in direction. test.x = bx + dx * h; test.y = by + dy * h; if (bounds.Contains(test) && IsPointInPolygon(test, contour)) { return test; } // Search in opposite direction (see NOTE above). test.x = bx - dx * h; test.y = by - dy * h; if (bounds.Contains(test) && IsPointInPolygon(test, contour)) { return test; } h = h / 2; } } throw new Exception(); }
public static TriangleNet.Geometry.Point FindPointInPolygon(SectionContour contour, List <SectionContour> otherContours, int limit, double eps = 2e-5) { List <Vertex> poly = contour.Points.Select(p => new Vertex(p.X, p.Y)).ToList(); var bounds = new TriangleNet.Geometry.Rectangle(); bounds.Expand(poly); int length = poly.Count; var test = new TriangleNet.Geometry.Point(); TriangleNet.Geometry.Point a, b, c; // Current corner points. double bx, by; double dx, dy; double h; var predicates = new RobustPredicates(); a = poly[0]; b = poly[1]; for (int i = 0; i < length; i++) { c = poly[(i + 2) % length]; // Corner point. bx = b.X; by = b.Y; // NOTE: if we knew the contour points were in counterclockwise order, we // could skip concave corners and search only in one direction. h = predicates.CounterClockwise(a, b, c); if (Math.Abs(h) < eps) { // Points are nearly co-linear. Use perpendicular direction. dx = (c.Y - a.Y) / 2; dy = (a.X - c.X) / 2; } else { // Direction [midpoint(a-c) -> corner point] dx = (a.X + c.X) / 2 - bx; dy = (a.Y + c.Y) / 2 - by; } // Move around the contour. a = b; b = c; h = 1.0; for (int j = 0; j < limit; j++) { // Search in direction. test.X = bx + dx * h; test.Y = by + dy * h; if (bounds.Contains(test) && IsPointInPolygon(test, contour, otherContours)) { return(test); } // Search in opposite direction (see NOTE above). test.X = bx - dx * h; test.Y = by - dy * h; if (bounds.Contains(test) && IsPointInPolygon(test, contour, otherContours)) { return(test); } h = h / 2; } } throw new Exception(); }