layout: implement creation and return of the apex

Apex is the dot positioned at the center of a zone that is used to
terminate and tie any band ending in the zone.
This commit is contained in:
Mikolaj Wielgus 2024-05-02 01:21:00 +02:00
parent ea22ba705c
commit 5664b73494
2 changed files with 51 additions and 6 deletions

View File

@ -6,7 +6,7 @@ use crate::{
drawing::{
bend::LooseBendWeight,
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
graph::{PrimitiveIndex, PrimitiveWeight, Retag},
graph::{GetLayer, PrimitiveIndex, PrimitiveWeight, Retag},
rules::RulesTrait,
seg::{
FixedSegIndex, FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SeqLooseSegIndex,
@ -17,16 +17,17 @@ use crate::{
Drawing, Infringement, LayoutException,
},
geometry::{
compound::CompoundManagerTrait, poly::PolyShape, BendWeightTrait, DotWeightTrait,
GenericNode, Geometry, GeometryLabel, GetWidth, SegWeightTrait,
compound::CompoundManagerTrait, poly::PolyShape, shape::ShapeTrait, BendWeightTrait,
DotWeightTrait, GenericNode, Geometry, GeometryLabel, GetWidth, SegWeightTrait,
},
graph::{GenericIndex, GetNodeIndex},
layout::{
connectivity::{
BandIndex, BandWeight, ConnectivityLabel, ConnectivityWeight, ContinentIndex,
},
zone::{PourZoneIndex, SolidZoneIndex, Zone, ZoneWeight},
zone::{GetMaybeApex, MakePolyShape, PourZoneIndex, SolidZoneIndex, Zone, ZoneWeight},
},
math::Circle,
};
pub type NodeIndex = GenericNode<PrimitiveIndex, GenericIndex<ZoneWeight>>;
@ -207,6 +208,25 @@ impl<R: RulesTrait> Layout<R> {
.compound_members(GenericIndex::new(zone.node_index()))
}
pub fn zone_apex(&mut self, zone: GenericIndex<ZoneWeight>) -> FixedDotIndex {
if let Some(apex) = self.zone(zone).maybe_apex() {
apex
} else {
self.add_zone_fixed_dot(
FixedDotWeight {
circle: Circle {
pos: self.zone(zone).shape().center(),
r: 0.0,
},
layer: self.zone(zone).layer(),
maybe_net: None,
},
zone,
)
.unwrap()
}
}
pub fn drawing(&self) -> &Drawing<ZoneWeight, R> {
&self.drawing
}

View File

@ -5,9 +5,9 @@ use petgraph::stable_graph::NodeIndex;
use crate::{
drawing::{
dot::DotIndex,
dot::{DotIndex, FixedDotIndex},
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag},
primitive::{GenericPrimitive, Primitive},
primitive::{GenericPrimitive, GetLimbs, Primitive},
rules::RulesTrait,
Drawing,
},
@ -21,6 +21,11 @@ pub trait MakePolyShape {
fn shape(&self) -> PolyShape;
}
#[enum_dispatch]
pub trait GetMaybeApex {
fn maybe_apex(&self) -> Option<FixedDotIndex>;
}
#[derive(Debug)]
pub struct Zone<'a, R: RulesTrait> {
pub index: GenericIndex<ZoneWeight>,
@ -72,6 +77,26 @@ impl<'a, R: RulesTrait> MakePolyShape for Zone<'a, R> {
}
}
impl<'a, R: RulesTrait> GetMaybeApex for Zone<'a, R> {
fn maybe_apex(&self) -> Option<FixedDotIndex> {
self.layout
.drawing()
.geometry()
.compound_members(self.index)
.find_map(|primitive_node| {
if let PrimitiveIndex::FixedDot(dot) = primitive_node {
if self.layout.drawing().primitive(dot).segs().is_empty()
&& self.layout.drawing().primitive(dot).bends().is_empty()
{
return Some(dot);
}
}
None
})
}
}
#[enum_dispatch(GetLayer, GetMaybeNet)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ZoneWeight {