public void WhenHeightRangeIsLowerThanAnotherHeightRangeThenTheyAreNotOverlapping() { HeightRange heightRangeOne = new HeightRange(10, 20, 15); HeightRange heightRangeTwo = new HeightRange(2, 6, 5); Assert.That(heightRangeTwo.IsOverlappingWith(heightRangeOne), Is.False); }
public void WhenHeightRangeIsEncompassedByAnotherHeightRangeThenTheyAreOverlapping() { HeightRange heightRangeOne = new HeightRange(1, 20, 15); HeightRange heightRangeTwo = new HeightRange(2, 6, 5); Assert.That(heightRangeTwo.IsOverlappingWith(heightRangeOne), Is.True); }
public void WhenHeightRangeHasMaxEqualToMinOfOtherHeightRangeThenTheyAreOverlapping() { HeightRange heightRangeOne = new HeightRange(6, 20, 15); HeightRange heightRangeTwo = new HeightRange(2, 6, 5); Assert.That(heightRangeTwo.IsOverlappingWith(heightRangeOne), Is.True); }
public void WhenHeightRangeHasMaxInBetweenMinAndMaxOfOtherHeightRangeThenTheyAreOverlapping() { HeightRange heightRangeOne = new HeightRange(6, 20, 15); HeightRange heightRangeTwo = new HeightRange(2, 8, 5); Assert.That(heightRangeTwo.IsOverlappingWith(heightRangeOne), Is.True); }
public void WhenValuesAreSetInConstructorThenTheyCanBeRetrieved() { HeightRange heightRange = new HeightRange(2, 5, 3); Assert.That(heightRange.Min, Is.EqualTo(2)); Assert.That(heightRange.Max, Is.EqualTo(5)); Assert.That(heightRange.GroundHeight, Is.EqualTo(3)); }
public void HeightRangeCanBeOneUnitLong() { HeightRange heightRange = new HeightRange(2, 2, 2); Assert.That(heightRange.Min, Is.EqualTo(2)); Assert.That(heightRange.Max, Is.EqualTo(2)); Assert.That(heightRange.GroundHeight, Is.EqualTo(2)); }
private void RemoveOverlaps(List <HeightRange> ranges, HeightRange newHeightRange) { ranges.FindAll(newHeightRange.IsOverlappingWith).ForEach(range => { newHeightRange.Min = Math.Min(newHeightRange.Min, range.Min); newHeightRange.Max = Math.Max(newHeightRange.Max, range.Max); }); ranges.RemoveAll(newHeightRange.IsOverlappingWith); }
private bool FindHeightInRangesForPosition(List <HeightRange> ranges, int positionHeight, out int recordedHeight) { HeightRange range = ranges.Find(r => r.IsHeightInRange(positionHeight)); if (range != null) { recordedHeight = range.GroundHeight; return(true); } recordedHeight = 0; return(false); }
/// <summary> /// This method will record <paramref name="height"/> as the ground level for all positions in between <paramref name="position"/> and <paramref name="height"/> inclusive. /// <para>If <paramref name="height"/> is -1, indicating no ground level was found, then the results will be recorded for all positions with the same x,z coordinates.</para> /// </summary> /// <param name="position">The starting position, that maps to this ground height.</param> /// <param name="height">The ground height for the given position, and all positions in between</param> public void CacheGroundPositionForLocation(Vector3i position, int height) { Vector2i queryPosition = new Vector2i(position.x, position.z); List <HeightRange> ranges = GetRangesForPosition(queryPosition); HeightRange newHeightRange = GenerateHeightRangeFor(position.y, height); RemoveOverlaps(ranges, newHeightRange); ranges.Add(newHeightRange); groundForPosition[queryPosition] = ranges; }
public static HeightRange FromBaseObject(BaseObject baseObj) { if (baseObj == null || baseObj.NativeObject == IntPtr.Zero) { return(null); } HeightRange obj = baseObj as HeightRange; if (object.Equals(obj, null)) { obj = new HeightRange(CreatedWhenConstruct.CWC_NotToCreate); obj.BindNativeObject(baseObj.NativeObject, "CHeightRange"); obj.IncreaseCast(); } return(obj); }
protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; ele.TryPathTo("Density", true, out subEle); subEle.Value = Density.ToString(); ele.TryPathTo("Slope/Min", true, out subEle); subEle.Value = MinSlope.ToString(); ele.TryPathTo("Slope/Max", true, out subEle); subEle.Value = MaxSlope.ToString(); WriteUnused1XML(ele, master); ele.TryPathTo("UnitFromWater/Amount", true, out subEle); subEle.Value = UnitFromWaterAmount.ToString(); WriteUnused2XML(ele, master); ele.TryPathTo("UnitFromWater/Type", true, out subEle); subEle.Value = UnitFromWaterType.ToString(); ele.TryPathTo("PositionRange", true, out subEle); subEle.Value = PositionRange.ToString("G15"); ele.TryPathTo("HeightRange", true, out subEle); subEle.Value = HeightRange.ToString("G15"); ele.TryPathTo("ColorRange", true, out subEle); subEle.Value = ColorRange.ToString("G15"); ele.TryPathTo("WavePeriod", true, out subEle); subEle.Value = WavePeriod.ToString("G15"); ele.TryPathTo("Flags", true, out subEle); subEle.Value = Flags.ToString(); WriteUnused3XML(ele, master); }
internal void Clear() { Profiler.BeginSample("Clear Index"); int index_size = m_IndexDim.x * (m_IndexDim.y + 1) * m_IndexDim.z; #if USE_INDEX_NATIVE_ARRAY NativeArray <int> arr = m_IndexBuffer.BeginWrite <int>(0, index_size); for (int i = 0; i < index_size; i++) { arr[i] = -1; } m_IndexBuffer.EndWrite <int>(index_size); #else for (int i = 0; i < m_TmpUpdater.Length; i++) { m_TmpUpdater[i] = -1; } for (int i = 0; i < m_IndexBuffer.count; i += m_TmpUpdater.Length) { UpdateIndexData(m_TmpUpdater, 0, i, Mathf.Min(m_TmpUpdater.Length, m_IndexBuffer.count - i)); } #endif HeightRange hr = new HeightRange() { min = -1, cnt = 0 }; for (int i = 0; i < m_HeightRanges.Length; i++) { m_HeightRanges[i] = hr; } m_VoxelToBricks.Clear(); m_BricksToVoxels.Clear(); Profiler.EndSample(); }
public void WhenHeightIsGreaterThanMaxThenItIsNotInRange() { HeightRange heightRange = new HeightRange(2, 8, 5); Assert.That(heightRange.IsHeightInRange(10), Is.False); }
public void WhenHeightIsLessThanMinThenItIsNotInRange() { HeightRange heightRange = new HeightRange(2, 8, 5); Assert.That(heightRange.IsHeightInRange(1), Is.False); }
public void WhenGroundHeightIsChangedToBeHigherThanMaxThenExceptionIsThrown() { HeightRange heightRange = new HeightRange(2, 5, 3); Assert.That(() => heightRange.GroundHeight = 6, Throws.ArgumentException); }
public BaseObject Create() { HeightRange emptyInstance = new HeightRange(CreatedWhenConstruct.CWC_NotToCreate); return(emptyInstance); }
public void WhenMaxIsChangedToExcludeGroundHeightThenExceptionIsThrown() { HeightRange heightRange = new HeightRange(2, 5, 3); Assert.That(() => heightRange.Max = 2, Throws.ArgumentException); }
public void WhenMaxIsChangedToBeSmallerThanMinThenExceptionIsThrown() { HeightRange heightRange = new HeightRange(2, 5, 3); Assert.That(() => heightRange.Max = 1, Throws.ArgumentException); }
public void WhenMinIsChangedToBeGreaterThanMaxThenExceptionIsThrown() { HeightRange heightRange = new HeightRange(2, 5, 3); Assert.That(() => heightRange.Min = 6, Throws.ArgumentException); }
/// <summary> /// This method can be used to quickly check whether or not any part of this height range is intersecting/overlapping with another height range. /// </summary> /// <param name="other">A height range to test against.</param> /// <returns>True IFF this height range is intersecting/overlapping with <paramref name="other"/></returns> public bool IsOverlappingWith(HeightRange other) { return(IsHeightInRange(other.min) || IsHeightInRange(other.max) || other.IsHeightInRange(min) || other.IsHeightInRange(max)); }
public void WhenHeightIsInBetweenMinAndMaxThenItIsInRange() { HeightRange heightRange = new HeightRange(2, 8, 5); Assert.That(heightRange.IsHeightInRange(4), Is.True); }
public void WhenHeightIsEqualToMaxThenItIsInRange() { HeightRange heightRange = new HeightRange(2, 8, 5); Assert.That(heightRange.IsHeightInRange(8), Is.True); }
void UpdateIndex(Vector3Int voxel, List <ReservedBrick> bricks, List <ushort> indices) { int base_offset = m_IndexDim.x * m_IndexDim.z; // clip voxel to index space Vector3Int vx_min, vx_max; ClipToIndexSpace(voxel, m_VoxelSubdivLevel, out vx_min, out vx_max); foreach (var rbrick in bricks) { // clip brick to clipped voxel int brick_cell_size = ProbeReferenceVolume.CellSize(rbrick.brick.subdivisionLevel); Vector3Int brick_min = rbrick.brick.position; Vector3Int brick_max = rbrick.brick.position + Vector3Int.one * brick_cell_size; brick_min.x = Mathf.Max(vx_min.x, brick_min.x - m_CenterRS.x); brick_min.y = Mathf.Max(vx_min.y, brick_min.y); brick_min.z = Mathf.Max(vx_min.z, brick_min.z - m_CenterRS.z); brick_max.x = Mathf.Min(vx_max.x, brick_max.x - m_CenterRS.x); brick_max.y = Mathf.Min(vx_max.y, brick_max.y); brick_max.z = Mathf.Min(vx_max.z, brick_max.z - m_CenterRS.z); int bsize_x = brick_max.x - brick_min.x; int bsize_z = brick_max.z - brick_min.z; if (bsize_x <= 0 || bsize_z <= 0) { continue; } for (int idx = 0; idx < brick_cell_size; idx++) { m_TmpUpdater[idx] = rbrick.flattenedIdx; } int posIS_x = m_CenterIS.x + brick_min.x; int posIS_z = m_CenterIS.z + brick_min.z; // iterate over z then x, as y needs special handling for updating the base offset for (int z = 0; z < bsize_z; z++) { for (int x = 0; x < bsize_x; x++) { int mx = (posIS_x + x) % m_IndexDim.x; int mz = (posIS_z + z) % m_IndexDim.z; int hoff_idx = mz * m_IndexDim.x + mx; HeightRange hr = m_HeightRanges[hoff_idx]; if (hr.min == -1) // untouched column { hr.min = brick_min.y; hr.cnt = Mathf.Min(brick_cell_size, m_IndexDim.y); UpdateIndexData(m_TmpUpdater, 0, base_offset + TranslateIndex(mx, 0, mz), hr.cnt); } else { // shift entire column upwards, but without pushing out existing indices int lowest_limit = hr.min - (m_IndexDim.y - hr.cnt); lowest_limit = Mathf.Max(brick_min.y, lowest_limit); int shift_cnt = Mathf.Max(0, hr.min - lowest_limit); int highest_limit = hr.min + m_IndexDim.y; if (shift_cnt == 0) { hr.cnt = Mathf.Max(0, Mathf.Min(m_IndexDim.y, brick_min.y + brick_cell_size - hr.min)); UpdateIndexData(m_TmpUpdater, 0, base_offset + TranslateIndex(mx, brick_min.y - hr.min, mz), Mathf.Min(brick_cell_size, highest_limit - brick_min.y)); } else { int indexTrans = TranslateIndex(mx, 0, mz); GetIndexData(ref m_TmpUpdater, shift_cnt, base_offset + indexTrans, hr.cnt); hr.min = lowest_limit; hr.cnt += shift_cnt; UpdateIndexData(m_TmpUpdater, 0, base_offset + indexTrans, hr.cnt); // restore pool idx array for (int cidx = shift_cnt; cidx < brick_cell_size; cidx++) { m_TmpUpdater[cidx] = rbrick.flattenedIdx; } } } // update the column offset m_HeightRanges[hoff_idx] = hr; m_TmpUpdater[m_TmpUpdater.Length - 1] = hr.min; UpdateIndexData(m_TmpUpdater, m_TmpUpdater.Length - 1, hoff_idx, 1); } } } }
void ClearVoxel(Vector3Int pos) { // clip voxel to index space Vector3Int volMin, volMax; ClipToIndexSpace(pos, m_VoxelSubdivLevel, out volMin, out volMax); int base_offset = m_IndexDim.x * m_IndexDim.z; int volCellSize = ProbeReferenceVolume.CellSize(m_VoxelSubdivLevel); int bsize_x = volMax.x - volMin.x; int bsize_z = volMax.z - volMin.z; if (bsize_x <= 0 || bsize_z <= 0) { return; } for (int idx = 0; idx < volCellSize; idx++) { m_TmpUpdater[idx] = -1; } int posIS_x = m_CenterIS.x + volMin.x; int posIS_z = m_CenterIS.z + volMin.z; // iterate over z then x, as y needs special handling for updating the base offset for (int z = 0; z < bsize_z; z++) { for (int x = 0; x < bsize_x; x++) { int mx = (posIS_x + x) % m_IndexDim.x; int mz = (posIS_z + z) % m_IndexDim.z; int hoff_idx = mz * m_IndexDim.x + mx; HeightRange hr = m_HeightRanges[hoff_idx]; if (hr.min == -1) { continue; } int indexTrans = TranslateIndex(mx, 0, mz); GetIndexData(ref m_TmpUpdater, 0, base_offset + indexTrans, hr.cnt); int start = volMin.y - hr.min; int end = Mathf.Min(start + volCellSize, m_IndexDim.y); start = Mathf.Max(start, 0); for (int i = start; i < end; i++) { m_TmpUpdater[i] = -1; } int hmin = m_IndexDim.y, hmax = -1; for (int i = 0; i < m_IndexDim.y; i++) { if (m_TmpUpdater[i] != -1) { hmin = Mathf.Min(hmin, i); hmax = Mathf.Max(hmax, i); } } bool all_cleared = hmin == m_IndexDim.y; if (all_cleared) { hr.min = -1; hr.cnt = 0; UpdateIndexData(m_TmpUpdater, 0, base_offset + indexTrans, m_IndexDim.y); } else { hr.min += hmin; hr.cnt = hmax - hmin; UpdateIndexData(m_TmpUpdater, hmin, base_offset + indexTrans, m_IndexDim.y - hmin); UpdateIndexData(m_TmpUpdater, 0, base_offset + indexTrans, hmin); } // update the column offset m_HeightRanges[hoff_idx] = hr; m_TmpUpdater[m_TmpUpdater.Length - 1] = hr.min; UpdateIndexData(m_TmpUpdater, m_TmpUpdater.Length - 1, hoff_idx, 1); } } }