mirror of https://codeberg.org/topola/topola.git
drawing: implement getting zone's polygon
This commit is contained in:
parent
1f9b04215a
commit
0e553fd0ba
|
|
@ -1,18 +1,25 @@
|
|||
use enum_dispatch::enum_dispatch;
|
||||
|
||||
use geo::{LineString, Point, Polygon};
|
||||
use petgraph::stable_graph::NodeIndex;
|
||||
|
||||
use crate::{
|
||||
drawing::{
|
||||
dot::DotIndex,
|
||||
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag},
|
||||
primitive::{GenericPrimitive, Primitive},
|
||||
rules::RulesTrait,
|
||||
Drawing,
|
||||
},
|
||||
geometry::GetPos,
|
||||
graph::{GenericIndex, GetNodeIndex},
|
||||
};
|
||||
|
||||
#[enum_dispatch(GetNodeIndex)]
|
||||
pub trait MakePolygon {
|
||||
fn polygon<R: RulesTrait>(&self, drawing: &Drawing<R>) -> Polygon;
|
||||
}
|
||||
|
||||
#[enum_dispatch(GetNodeIndex, MakePolygon)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum ZoneIndex {
|
||||
Solid(SolidZoneIndex),
|
||||
|
|
@ -46,6 +53,27 @@ impl<'a> GetMaybeNet for SolidZoneWeight {
|
|||
|
||||
pub type SolidZoneIndex = GenericIndex<SolidZoneWeight>;
|
||||
|
||||
impl MakePolygon for SolidZoneIndex {
|
||||
fn polygon<R: RulesTrait>(&self, drawing: &Drawing<R>) -> Polygon {
|
||||
Polygon::new(
|
||||
LineString::from(
|
||||
drawing
|
||||
.geometry()
|
||||
.members(GenericIndex::<ZoneWeight>::new(self.node_index()))
|
||||
.filter_map(|primitive_node| {
|
||||
if let Ok(dot) = DotIndex::try_from(primitive_node) {
|
||||
Some(drawing.geometry().dot_weight(dot).pos())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<Point>>(),
|
||||
),
|
||||
vec![],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct PourZoneWeight {
|
||||
pub layer: u64,
|
||||
|
|
@ -65,3 +93,24 @@ impl<'a> GetMaybeNet for PourZoneWeight {
|
|||
}
|
||||
|
||||
pub type PourZoneIndex = GenericIndex<PourZoneWeight>;
|
||||
|
||||
impl MakePolygon for PourZoneIndex {
|
||||
fn polygon<R: RulesTrait>(&self, drawing: &Drawing<R>) -> Polygon {
|
||||
Polygon::new(
|
||||
LineString::from(
|
||||
drawing
|
||||
.geometry()
|
||||
.members(GenericIndex::<ZoneWeight>::new(self.node_index()))
|
||||
.filter_map(|primitive_node| {
|
||||
if let Ok(dot) = DotIndex::try_from(primitive_node) {
|
||||
Some(drawing.geometry().dot_weight(dot).pos())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<Point>>(),
|
||||
),
|
||||
vec![],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue