public DistanceGrid(Shape shape, Scalar spacing) { if (shape == null) { throw new ArgumentNullException("shape"); } if (spacing <= 0) { throw new ArgumentOutOfRangeException("spacing"); } //prepare the shape. Matrix2D old = shape.Matrix; Matrix2D ident = Matrix2D.Identity; shape.ApplyMatrix(ref ident); shape.CalcBoundingBox2D(); this.box = shape.BoundingBox2D; this.gridSpacing = spacing; this.gridSpacingInv = 1 / spacing; int xSize = (int)Math.Ceiling((box.Upper.X - box.Lower.X) * gridSpacingInv) + 2; int ySize = (int)Math.Ceiling((box.Upper.Y - box.Lower.Y) * gridSpacingInv) + 2; this.nodes = new Scalar[xSize, ySize]; Vector2D vector; vector.X = box.Lower.X; for (int x = 0; x < xSize; ++x, vector.X += spacing) { vector.Y = box.Lower.Y; for (int y = 0; y < ySize; ++y, vector.Y += spacing) { nodes[x, y] = shape.GetDistance(vector); } } //restore the shape shape.ApplyMatrix(ref old); shape.CalcBoundingBox2D(); }