54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from inire.geometry.components import bend_fits_width, build_component
|
|
from inire.model import resolve_bend_geometry
|
|
from inire.seeds import Bend90Seed, SBendSeed, StraightSeed
|
|
|
|
if TYPE_CHECKING:
|
|
from inire.geometry.components import ComponentResult
|
|
from inire.geometry.primitives import Port
|
|
from inire.model import SearchOptions
|
|
from inire.seeds import PathSeed
|
|
|
|
|
|
def materialize_path_seed(
|
|
seed: PathSeed,
|
|
*,
|
|
start: Port,
|
|
net_width: float,
|
|
search: SearchOptions,
|
|
clearance: float,
|
|
) -> tuple[ComponentResult, ...] | None:
|
|
if any(isinstance(segment, (Bend90Seed, SBendSeed)) and not bend_fits_width(segment.radius, net_width) for segment in seed.segments):
|
|
return None
|
|
|
|
path: list[ComponentResult] = []
|
|
current = start
|
|
dilation = clearance / 2.0
|
|
bend_collision_type, bend_physical_geometry = resolve_bend_geometry(search)
|
|
bend_clip_margin = search.bend_clip_margin
|
|
|
|
for segment in seed.segments:
|
|
if isinstance(segment, StraightSeed):
|
|
kind, parameters = "straight", (segment.length,)
|
|
elif isinstance(segment, Bend90Seed):
|
|
kind, parameters = "bend90", (segment.radius, segment.direction)
|
|
elif isinstance(segment, SBendSeed):
|
|
kind, parameters = "sbend", (segment.offset, segment.radius)
|
|
else:
|
|
raise TypeError(f"Unsupported seed segment: {type(segment)!r}")
|
|
component = build_component(
|
|
current,
|
|
net_width,
|
|
kind,
|
|
parameters,
|
|
collision_type=bend_collision_type,
|
|
physical_geometry_type=bend_physical_geometry,
|
|
clip_margin=bend_clip_margin,
|
|
dilation=dilation,
|
|
)
|
|
path.append(component)
|
|
current = component.end_port
|
|
return tuple(path)
|