Preflight component geometry before tessellation
This commit is contained in:
parent
286caa273b
commit
c480871f07
1 changed files with 252 additions and 113 deletions
|
|
@ -2,7 +2,9 @@ from __future__ import annotations
|
|||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from inire.geometry.components import bend_fits_width, build_component
|
||||
from inire.geometry.components import (
|
||||
ComponentPreparationError, bend_fits_width, build_component, component_endpoint, prepare_component_sampling,
|
||||
)
|
||||
from inire.model import resolve_bend_geometry
|
||||
from inire.seeds import Bend90Seed, SBendSeed, StraightSeed
|
||||
|
||||
|
|
@ -30,6 +32,26 @@ def seed_width_error(seed: PathSeed, net_width: float) -> str | None:
|
|||
return None
|
||||
|
||||
|
||||
def seed_preparation_error(seed: PathSeed, *, start: Port, net_width: float, search: SearchOptions, clearance: float) -> str | None:
|
||||
proxy, physical = resolve_bend_geometry(search)
|
||||
for index, segment in enumerate(seed.segments, start=1):
|
||||
kind, parameters = seed_move(segment)
|
||||
template = search.sbend_template(segment.offset, segment.radius, net_width) if isinstance(segment, SBendSeed) else None
|
||||
try:
|
||||
start = component_endpoint(start, kind, parameters)
|
||||
prepare_component_sampling(
|
||||
kind, parameters, net_width, collision_type=proxy, physical_geometry_type=physical,
|
||||
dilation=clearance / 2, sbend_outline=template.polygon if template is not None else None,
|
||||
)
|
||||
except (ComponentPreparationError, OverflowError) as exc:
|
||||
return f"segment {index} ({type(segment).__name__}) {exc}"
|
||||
return None
|
||||
|
||||
|
||||
class SeedMaterializationError(ValueError):
|
||||
"""A supplied seed cannot be materialized."""
|
||||
|
||||
|
||||
def materialize_path_seed(
|
||||
seed: PathSeed,
|
||||
*,
|
||||
|
|
@ -37,31 +59,44 @@ def materialize_path_seed(
|
|||
net_width: float,
|
||||
search: SearchOptions,
|
||||
clearance: float,
|
||||
bounds: tuple[float, float, float, float] | None = None,
|
||||
diagnostic: bool = False,
|
||||
) -> tuple[ComponentResult, ...] | None:
|
||||
if seed_width_error(seed, net_width) is not None:
|
||||
return None
|
||||
|
||||
if diagnostic:
|
||||
error = seed_preparation_error(seed, start=start, net_width=net_width, search=search, clearance=clearance)
|
||||
if error is not None:
|
||||
raise SeedMaterializationError(error)
|
||||
|
||||
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:
|
||||
for index, segment in enumerate(seed.segments, start=1):
|
||||
kind, parameters = seed_move(segment)
|
||||
template = search.sbend_template(segment.offset, segment.radius, net_width) if isinstance(segment, SBendSeed) else None
|
||||
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,
|
||||
sbend_outline=template.polygon if template is not None else None,
|
||||
physical_length=search.bend_physical_length if kind == "bend90" else (template.length if template else None),
|
||||
)
|
||||
try:
|
||||
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,
|
||||
sbend_outline=template.polygon if template is not None else None,
|
||||
bounds=None if diagnostic else bounds,
|
||||
physical_length=search.bend_physical_length if kind == "bend90" else (template.length if template else None),
|
||||
)
|
||||
except (ComponentPreparationError, OverflowError) as exc:
|
||||
if diagnostic:
|
||||
raise SeedMaterializationError(f"segment {index} ({type(segment).__name__}) {exc}") from exc
|
||||
return None
|
||||
path.append(component)
|
||||
current = component.end_port
|
||||
return tuple(path)
|
||||
|
|
|
|||
Loading…
Reference in a new issue