/// <summary> /// Create Polygon from a group of points private static Path FromGroup(Path area) { Rect box = BoundBox(area); BitMatrix bm = Polygonizer.DrawPoints(area, box); // The matrix holding the points Path polygon = new Path(); // the result // find highest & leftmost point int i = 0; for (i = 0; i < bm.bits.Length; i++) { if (bm.bits[i]) { break; } i++; } IntPoint currP = new IntPoint(); IntPoint nextP = new IntPoint(); IntPoint guessP = new IntPoint(); Direction currDirBack = Direction.NE; // since the first point is uppermost & leftmost, prevDirBack can never be W Direction nextDirBack = Direction.E; // a random direction different from prevDirBack // extract the coordinate currP.X = i % bm.width; currP.Y = i / bm.width; IntPoint startP = new IntPoint(currP); // the position to look at based on the curr point // NE SE SE // NE CT SW // NW NW SW do { // make guessP the next moore neighbor switch (currDirBack) { case Direction.N: goto case Direction.NE; case Direction.NE: guessP.X = currP.X + 1; guessP.Y = currP.Y + 1; break; case Direction.E: goto case Direction.SE; case Direction.SE: guessP.X = currP.X - 1; guessP.Y = currP.Y + 1; break; case Direction.S: goto case Direction.SW; case Direction.SW: guessP.X = currP.X - 1; guessP.Y = currP.Y - 1; break; case Direction.W: goto case Direction.NW; case Direction.NW: guessP.X = currP.X + 1; guessP.Y = currP.Y - 1; break; } nextP = bm.nextNeighbour(currP, guessP); nextDirBack = BitMatrix.getDirection(nextP, currP); // only add the curr point if it is a true vertex if (nextDirBack != currDirBack) { polygon.Add(new IntPoint(currP.X + box.xMin, currP.Y + box.yMin)); currDirBack = nextDirBack; } currP = nextP; } while (nextP != startP); RDP(polygon); return(polygon); }