/// <summary> /// Calculates line buffer like sense areas based on current positioning of blocks. /// </summary> private void doCalculateSenseAreas() { // No blocks: no areas. Just a defensive check. if (positionedBlocks == null || positionedBlocks.Length == 0) { return; } List <SenseArea> areas = new List <SenseArea>(); ushort currX = ushort.MinValue; ushort currY = (ushort)positionedBlocks[0].LocY; ushort lineIx = 0; short senseIx = -1; Block? bLast = null; PositionedBlock? pbLast = null; for (int i = 0; i != positionedBlocks.Length; ++i) { Block b = measuredBlocks[i]; PositionedBlock pb = positionedBlocks[i]; // Starting a new sense? // Moving to new line? // -> If we've had a range before, that's a new sense area. if (b.FirstInCedictSense || pb.LocY != currY) { // We've been building a block already if (bLast.HasValue) { SenseArea area = new SenseArea(lineIx, currX, (ushort)(pbLast.Value.LocX + bLast.Value.Width), (ushort)senseIx); areas.Add(area); } // Increment either sense index or line index or both if (b.FirstInCedictSense) { ++senseIx; } if (pb.LocY != currY) { ++lineIx; } currY = (ushort)pb.LocY; currX = (ushort)pb.LocX; } // Current block is next last block bLast = b; pbLast = pb; } // Finish off very last block SenseArea last = new SenseArea(lineIx, currX, (ushort)(pbLast.Value.LocX + bLast.Value.Width), (ushort)senseIx); areas.Add(last); // We're done here. senseAreas = areas.ToArray(); }
/// <summary> /// Calculates line buffer like sense areas based on current positioning of blocks. /// </summary> private void doCalculateSenseAreas() { // No blocks: no areas. Just a defensive check. if (positionedBlocks == null || positionedBlocks.Length == 0) return; List<SenseArea> areas = new List<SenseArea>(); ushort currX = ushort.MinValue; ushort currY = (ushort)positionedBlocks[0].LocY; ushort lineIx = 0; short senseIx = -1; Block? bLast = null; PositionedBlock? pbLast = null; for (int i = 0; i != positionedBlocks.Length; ++i) { Block b = measuredBlocks[i]; PositionedBlock pb = positionedBlocks[i]; // Starting a new sense? // Moving to new line? // -> If we've had a range before, that's a new sense area. if (b.FirstInCedictSense || pb.LocY != currY) { // We've been building a block already if (bLast.HasValue) { SenseArea area = new SenseArea(lineIx, currX, (ushort)(pbLast.Value.LocX + bLast.Value.Width), (ushort)senseIx); areas.Add(area); } // Increment either sense index or line index or both if (b.FirstInCedictSense) ++senseIx; if (pb.LocY != currY) ++lineIx; currY = (ushort)pb.LocY; currX = (ushort)pb.LocX; } // Current block is next last block bLast = b; pbLast = pb; } // Finish off very last block SenseArea last = new SenseArea(lineIx, currX, (ushort)(pbLast.Value.LocX + bLast.Value.Width), (ushort)senseIx); areas.Add(last); // We're done here. senseAreas = areas.ToArray(); }