public DistanceGrid(IHasArea shape, Scalar spacing)
        {
            if (shape == null) { throw new ArgumentNullException("shape"); }
            if (spacing <= 0) { throw new ArgumentOutOfRangeException("spacing"); }
            Matrix2x3 ident = Matrix2x3.Identity;
            shape.CalcBoundingRectangle(ref ident, out this.rect);
            
            this.gridSpacing = spacing;
            this.gridSpacingInv = 1 / spacing;
            int xSize = (int)Math.Ceiling((rect.Max.X - rect.Min.X) * gridSpacingInv) + 2;
            int ySize = (int)Math.Ceiling((rect.Max.Y - rect.Min.Y) * gridSpacingInv) + 2;

            this.nodes = new Scalar[xSize][];
            for (int index = 0; index < xSize; ++index)
            {
                this.nodes[index] = new Scalar[ySize];
            }
            Vector2D point;
            point.X = rect.Min.X;
            for (int x = 0; x < xSize; ++x, point.X += gridSpacing)
            {
                point.Y = rect.Min.Y;
                for (int y = 0; y < ySize; ++y, point.Y += gridSpacing)
                {
                    shape.GetDistance(ref point, out nodes[x][y]);
                }
            }
        }
Beispiel #2
0
        public double GetArea(IHasArea figure)
        {
            if (figure == null)
            {
                throw new ArgumentNullException(nameof(figure));
            }

            return(figure.CalculateArea());
        }
Beispiel #3
0
        public DistanceGrid(IHasArea shape, Scalar spacing)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }
            if (spacing <= 0)
            {
                throw new ArgumentOutOfRangeException("spacing");
            }
            Matrix2x3 ident = Matrix2x3.Identity;

            shape.CalcBoundingRectangle(ref ident, out this.rect);

            this.gridSpacing    = spacing;
            this.gridSpacingInv = 1 / spacing;
            int xSize = (int)Math.Ceiling((rect.Max.X - rect.Min.X) * gridSpacingInv) + 2;
            int ySize = (int)Math.Ceiling((rect.Max.Y - rect.Min.Y) * gridSpacingInv) + 2;

            this.nodes = new Scalar[xSize][];
            for (int index = 0; index < xSize; ++index)
            {
                this.nodes[index] = new Scalar[ySize];
            }
            Vector2D point;

            point.X = rect.Min.X;
            for (int x = 0; x < xSize; ++x, point.X += gridSpacing)
            {
                point.Y = rect.Min.Y;
                for (int y = 0; y < ySize; ++y, point.Y += gridSpacing)
                {
                    shape.GetDistance(ref point, out nodes[x][y]);
                }
            }
        }