Table of Contents

Class BorderChainMerger

Namespace
Map.Rendering.Border
Assembly
MapAssembly.dll

Merges multiple border pixel chains into single connected polylines Extracted from BorderCurveExtractor for single responsibility

Contains logic for:

  • Merging multiple chains by finding closest endpoints
  • U-turn detection and rejection to prevent bad geometry
  • Chain simplification (keeping only longest chains)
  • Junction bridging (connecting gaps to junctions via BFS)
public class BorderChainMerger
Inheritance
object
BorderChainMerger

Constructors

BorderChainMerger(int, int, Color32[], Dictionary<Vector2, HashSet<ushort>>)

public BorderChainMerger(int width, int height, Color32[] idPixels, Dictionary<Vector2, HashSet<ushort>> junctions)

Parameters

width int
height int
idPixels Color32[]
junctions Dictionary<Vector2, HashSet<ushort>>

Methods

BridgeToJunction(Vector2, ushort, ushort, List<Vector2>)

Bridge disconnected border pixels to junction using BFS pathfinding Finds shortest path along valid border pixels to connect gaps

public int BridgeToJunction(Vector2 junctionPos, ushort provinceA, ushort provinceB, List<Vector2> borderPixels)

Parameters

junctionPos Vector2
provinceA ushort
provinceB ushort
borderPixels List<Vector2>

Returns

int

MergeChains(List<List<Vector2>>)

Merge multiple chains into single polyline using intelligent endpoint matching Includes U-turn detection to prevent bad geometry

public List<Vector2> MergeChains(List<List<Vector2>> chains)

Parameters

chains List<List<Vector2>>

Returns

List<Vector2>

MergeChainsSimple(List<List<Vector2>>, ushort, ushort)

Simple chain merging without U-turn angle check Uses self-intersection detection instead (more robust)

public List<Vector2> MergeChainsSimple(List<List<Vector2>> chains, ushort provinceA = 0, ushort provinceB = 0)

Parameters

chains List<List<Vector2>>
provinceA ushort
provinceB ushort

Returns

List<Vector2>