Editor class that implements IArchRoadNetwork. It builds a list of ArchRoadJunctions from ArchJunction nodes derived from a plan and kit, names junctions by the distinct road ids on their legs, and computes a 2D extent (bounds) from leg frames and reach values.
namespace Sunless.Architecture;
public sealed class ArchRoadNetwork : IArchRoadNetwork
{
public IReadOnlyList<ArchRoadJunction> Junctions( ArchPlan plan, ArchKit kit )
{
return ArchJunction.Derived( plan, kit ).Select( junction => new ArchRoadJunction(
NameOf( junction ), junction, Extent( junction ) ) ).ToList();
}
public static string NameOf( ArchJunctionNode junction )
{
var roads = junction.Legs.Select( leg => leg.Road.Id ).Distinct().OrderBy( id => id );
return $"Junction_{string.Join( "_", roads )}";
}
static ArchExtent Extent( ArchJunctionNode junction )
{
var extent = new ArchExtent();
foreach ( var leg in junction.Legs )
{
var position = leg.Frame().Position;
extent.Add( new Vector2( position.x, position.y ), position.z - leg.Reach, position.z + leg.Reach );
}
return extent;
}
}