public static Shape[] findThinShapes(Shape shape, int n, int outerTryLimit, int innerTryLimit, double thinnessLimit, int areaLowerLimit, int areaHigherLimit) { Random r = new Random(); Shape workingShape = (Shape)shape.Clone(); Shape[] thinShapes = new Shape[n]; int outerTries = 0; int maxFound = 0; int i = 0; while ((i < n) && (outerTries < outerTryLimit)) { Shape thinShape = null; int innerTries = 0; while ((thinShape == null) && (innerTries < innerTryLimit)) { // this may be real slow Point? randomPoint = workingShape.getPoint(r.Next(shape.Set.Count)); thinShape = ImageAlgorithms.reduceShapeToAreaAndRatio(workingShape, randomPoint, thinnessLimit, areaLowerLimit, areaHigherLimit); innerTries++; } if (thinShape == null) { outerTries++; i = 0; workingShape = (Shape)shape.Clone(); continue; } thinShapes[i] = thinShape; workingShape.subtract(thinShape); i++; if (i > maxFound) { maxFound = i; } } //System.out.format("most thinshapes found: %d\n", maxFound); if (outerTries == outerTryLimit) { //return null; return thinShapes; } return thinShapes; }