private void Connect(List <Point> points, int j, Rectangle bounds, bool Closing) { Point rightPoint = points[points.Count - 1]; Edge nEdge = edges[j]; Orientation nOrient = edgeOrientations[j]; Point nPoint = nEdge.GetClippedEnds()[nOrient]; if (CloseEnough(rightPoint, nPoint)) { if ((rightPoint.x != nPoint.x) && (rightPoint.y != nPoint.y)) { int rightCheck = BoundsCheck.Check(rightPoint, bounds); int nCheck = BoundsCheck.Check(nPoint, bounds); double pX; double pY; if ((rightCheck & BoundsCheck.RIGHT) != 0) { pX = bounds.right; if ((nCheck & BoundsCheck.BOTTOM) != 0) { pY = bounds.bottom; points.Add(new Point(pX, pY)); } else if ((nCheck & BoundsCheck.TOP) != 0) { pY = bounds.top; points.Add(new Point(pX, pY)); } else if ((nCheck & BoundsCheck.LEFT) != 0) { if (((rightPoint.y - bounds.y + nPoint.y) - bounds.y) < bounds.height) { pY = bounds.top; } else { pY = bounds.bottom; } points.Add(new Point(pX, pY)); points.Add(new Point(bounds.left, pY)); } } else if ((rightCheck & BoundsCheck.LEFT) != 0) { pX = bounds.left; if ((nCheck & BoundsCheck.BOTTOM) != 0) { pY = bounds.bottom; points.Add(new Point(pX, pY)); } else if ((nCheck & BoundsCheck.TOP) != 0) { pY = bounds.top; points.Add(new Point(pX, pY)); } else if ((nCheck & BoundsCheck.RIGHT) != 0) { if (((rightPoint.y - bounds.y + nPoint.y) - bounds.y) < bounds.height) { pY = bounds.top; } else { pY = bounds.bottom; } points.Add(new Point(pX, pY)); points.Add(new Point(bounds.right, pY)); } } else if ((rightCheck & BoundsCheck.TOP) != 0) { pY = bounds.top; if ((nCheck & BoundsCheck.RIGHT) != 0) { pX = bounds.right; points.Add(new Point(pX, pY)); } else if ((nCheck & BoundsCheck.LEFT) != 0) { pX = bounds.left; points.Add(new Point(pX, pY)); } else if ((nCheck & BoundsCheck.BOTTOM) != 0) { if (((rightPoint.x - bounds.x + nPoint.x) - bounds.x) < bounds.width) { pX = bounds.left; } else { pX = bounds.right; } points.Add(new Point(pX, pY)); points.Add(new Point(pX, bounds.bottom)); } } else if ((rightCheck & BoundsCheck.BOTTOM) != 0) { pY = bounds.bottom; if ((nCheck & BoundsCheck.RIGHT) != 0) { pX = bounds.right; points.Add(new Point(pX, pY)); } else if ((nCheck & BoundsCheck.LEFT) != 0) { pX = bounds.left; points.Add(new Point(pX, pY)); } else if ((nCheck & BoundsCheck.TOP) != 0) { if (((rightPoint.x - bounds.x + nPoint.x) - bounds.x) < bounds.width) { pX = bounds.left; } else { pX = bounds.right; } points.Add(new Point(pX, pY)); points.Add(new Point(pX, bounds.top)); } } } if (Closing) { return; } points.Add(nPoint); } Point nRightPoint = nEdge.GetClippedEnds()[Orientation.Other(nOrient)]; if (!CloseEnough(points[0], nRightPoint)) { points.Add(nRightPoint); } }
private void Connect(ref List <Vector2f> points, int j, Rectf bounds, bool closingUp = false) { Vector2f rightPoint = points[points.Count - 1]; Edge newEdge = edges[j]; LR newOrientation = edgeOrientations[j]; // The point that must be conected to rightPoint: Vector2f newPoint = newEdge.ClippedEnds[newOrientation]; if (!CloseEnough(rightPoint, newPoint)) { // The points do not coincide, so they must have been clipped at the bounds; // see if they are on the same border of the bounds: if (rightPoint.x != newPoint.x && rightPoint.y != newPoint.y) { // They are on different borders of the bounds; // insert one or two corners of bounds as needed to hook them up: // (NOTE this will not be correct if the region should take up more than // half of the bounds rect, for then we will have gone the wrong way // around the bounds and included the smaller part rather than the larger) int rightCheck = BoundsCheck.Check(rightPoint, bounds); int newCheck = BoundsCheck.Check(newPoint, bounds); float px, py; if ((rightCheck & BoundsCheck.RIGHT) != 0) { px = bounds.right; if ((newCheck & BoundsCheck.BOTTOM) != 0) { py = bounds.bottom; points.Add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.TOP) != 0) { py = bounds.top; points.Add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.LEFT) != 0) { if (rightPoint.y - bounds.y + newPoint.y - bounds.y < bounds.height) { py = bounds.top; } else { py = bounds.bottom; } points.Add(new Vector2f(px, py)); points.Add(new Vector2f(bounds.left, py)); } } else if ((rightCheck & BoundsCheck.LEFT) != 0) { px = bounds.left; if ((newCheck & BoundsCheck.BOTTOM) != 0) { py = bounds.bottom; points.Add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.TOP) != 0) { py = bounds.top; points.Add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.RIGHT) != 0) { if (rightPoint.y - bounds.y + newPoint.y - bounds.y < bounds.height) { py = bounds.top; } else { py = bounds.bottom; } points.Add(new Vector2f(px, py)); points.Add(new Vector2f(bounds.right, py)); } } else if ((rightCheck & BoundsCheck.TOP) != 0) { py = bounds.top; if ((newCheck & BoundsCheck.RIGHT) != 0) { px = bounds.right; points.Add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.LEFT) != 0) { px = bounds.left; points.Add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.BOTTOM) != 0) { if (rightPoint.x - bounds.x + newPoint.x - bounds.x < bounds.width) { px = bounds.left; } else { px = bounds.right; } points.Add(new Vector2f(px, py)); points.Add(new Vector2f(px, bounds.bottom)); } } else if ((rightCheck & BoundsCheck.BOTTOM) != 0) { py = bounds.bottom; if ((newCheck & BoundsCheck.RIGHT) != 0) { px = bounds.right; points.Add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.LEFT) != 0) { px = bounds.left; points.Add(new Vector2f(px, py)); } else if ((newCheck & BoundsCheck.TOP) != 0) { if (rightPoint.x - bounds.x + newPoint.x - bounds.x < bounds.width) { px = bounds.left; } else { px = bounds.right; } points.Add(new Vector2f(px, py)); points.Add(new Vector2f(px, bounds.top)); } } } if (closingUp) { // newEdge's ends have already been added return; } points.Add(newPoint); } Vector2f newRightPoint = newEdge.ClippedEnds[LR.Other(newOrientation)]; if (!CloseEnough(points[0], newRightPoint)) { points.Add(newRightPoint); } }