public void Includes() { var bound = new BoundingIntegerExtent2D(1, 1, 100, 100); bound.Includes(101, 101).Should().BeFalse(); bound.Includes(0, 0).Should().BeFalse(); // Int version bound.Includes(1, 1).Should().BeTrue(); bound.Includes(1, 100).Should().BeTrue(); bound.Includes(100, 100).Should().BeTrue(); bound.Includes(100, 1).Should().BeTrue(); // UInt version bound.Includes(1U, 1U).Should().BeTrue(); bound.Includes(1U, 100U).Should().BeTrue(); bound.Includes(100U, 100U).Should().BeTrue(); bound.Includes(100U, 1U).Should().BeTrue(); }
public static void ConstructSubgridSpatialAndPositionalMask(ILeafSubGrid SubGridAsLeaf, ISiteModel SiteModel, ICombinedFilter Filter, bool AHasOverrideSpatialCellRestriction, BoundingIntegerExtent2D AOverrideSpatialCellRestriction, SubGridTreeBitmapSubGridBits PDMask, SubGridTreeBitmapSubGridBits FilterMask) { if (Filter == null || !Filter.SpatialFilter.HasSpatialOrPositionalFilters) { PDMask.Fill(); FilterMask.Fill(); return; } var originX = SubGridAsLeaf.OriginX; var originY = SubGridAsLeaf.OriginY; var cellSize = SiteModel.CellSize; // Get the world location of the origin position SiteModel.Grid.GetCellCenterPosition(originX, originY, out var OX, out var OY); var SpatialFilter = Filter.SpatialFilter; // Attempt to satisfy the calculation below on the basis of the sub grid wholly residing in the override and filter spatial restrictions if (SpatialFilter.Fence.IncludesExtent(new BoundingWorldExtent3D(OX, OY, OX + cellSize * SubGridTreeConsts.SubGridTreeDimension, OY + cellSize * SubGridTreeConsts.SubGridTreeDimension))) { // The extent of the sub grid is wholly contained in the filter, therefore there is no need to iterate though all the cells // individually... FilterMask.Fill(); // ... unless there is an override spatial cell restriction that does not enclose the extent of the sub grid if (AHasOverrideSpatialCellRestriction && !AOverrideSpatialCellRestriction.Encloses(new BoundingIntegerExtent2D((int)originX, (int)originY, (int)originX + SubGridTreeConsts.SubGridTreeDimension, (int)originY + SubGridTreeConsts.SubGridTreeDimension))) { for (byte I = 0; I < SubGridTreeConsts.SubGridTreeDimension; I++) { for (byte J = 0; J < SubGridTreeConsts.SubGridTreeDimension; J++) { if (!AOverrideSpatialCellRestriction.Includes(originX + I, originY + J)) { FilterMask.ClearBit(I, J); } } } } } else { // Perform the calculation the long hand way // ... Idea: Invert row and column order of calculation below to get and set bits based on an entire column of bits FilterMask.Clear(); // Construct the filter mask based on the spatial and location (square/circle/polygonal) filtering double CX = OX; for (byte I = 0; I < SubGridTreeConsts.SubGridTreeDimension; I++) { int OriginXPlusI = originX + I; double CY = OY; // Set to the first row in the column about to be processed for (byte J = 0; J < SubGridTreeConsts.SubGridTreeDimension; J++) { if (AHasOverrideSpatialCellRestriction && !AOverrideSpatialCellRestriction.Includes((int)OriginXPlusI, (int)(originY + J))) { // Do nothing } else { // SiteModel.Grid.GetCellCenterPosition(OriginXPlusI, originY + J, out CX, out CY); if (SpatialFilter.IsCellInSelection(CX, CY)) { FilterMask.SetBit(I, J); } } CY += cellSize; // Move to next row } CX += cellSize; // Move to next column } } }