refactor(geometry::poly): PolyShape should be equal to Polygon

This commit is contained in:
Alain Emilia Anna Zscheile 2025-01-03 19:52:40 +01:00 committed by mikolaj
parent fae1f4d7bc
commit c7d50fd79f
11 changed files with 52 additions and 66 deletions

View File

@ -19,7 +19,7 @@ use topola::{
geometry::shape::{AccessShape, Shape}, geometry::shape::{AccessShape, Shape},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetPetgraphIndex},
layout::{ layout::{
poly::{MakePolyShape, PolyWeight}, poly::{MakePolygon, PolyWeight},
via::ViaWeight, via::ViaWeight,
CompoundWeight, Layout, NodeIndex, CompoundWeight, Layout, NodeIndex,
}, },

View File

@ -5,7 +5,10 @@
use geo::{CoordsIter, Point, Polygon}; use geo::{CoordsIter, Point, Polygon};
use rstar::AABB; use rstar::AABB;
use topola::{ use topola::{
geometry::primitive::{AccessPrimitiveShape, PrimitiveShape}, geometry::{
primitive::{AccessPrimitiveShape, PrimitiveShape},
shape::AccessShape,
},
math::Circle, math::Circle,
}; };
@ -54,7 +57,7 @@ impl<'a> Painter<'a> {
self.ui.painter().add(epaint_shape); self.ui.painter().add(epaint_shape);
if self.paint_bboxes { if self.paint_bboxes {
self.paint_bbox(AccessPrimitiveShape::bbox(shape, 0.0)); self.paint_bbox(AccessShape::bbox(shape, 0.0));
} }
} }

View File

@ -19,7 +19,7 @@ use topola::{
primitive::MakePrimitiveShape, primitive::MakePrimitiveShape,
}, },
geometry::{shape::AccessShape, GenericNode}, geometry::{shape::AccessShape, GenericNode},
layout::{poly::MakePolyShape, via::ViaWeight}, layout::{poly::MakePolygon, via::ViaWeight},
math::Circle, math::Circle,
}; };
@ -175,10 +175,7 @@ impl Viewport {
.normal .normal
}; };
painter.paint_polygon( painter.paint_polygon(&board.layout().poly(poly).shape(), color)
&board.layout().poly(poly).shape().polygon,
color,
)
} }
} }
} }

View File

@ -30,7 +30,7 @@ use crate::{
geometry::shape::AccessShape, geometry::shape::AccessShape,
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetPetgraphIndex},
layout::{ layout::{
poly::{MakePolyShape, PolyWeight}, poly::{MakePolygon, PolyWeight},
Layout, Layout,
}, },
triangulation::{GetTrianvertexNodeIndex, Triangulation}, triangulation::{GetTrianvertexNodeIndex, Triangulation},

View File

@ -28,7 +28,7 @@ use crate::{
geometry::{edit::ApplyGeometryEdit, shape::AccessShape, GenericNode}, geometry::{edit::ApplyGeometryEdit, shape::AccessShape, GenericNode},
graph::GenericIndex, graph::GenericIndex,
layout::{ layout::{
poly::{GetMaybeApex, MakePolyShape, PolyWeight}, poly::{GetMaybeApex, MakePolygon, PolyWeight},
CompoundWeight, Layout, LayoutEdit, NodeIndex, CompoundWeight, Layout, LayoutEdit, NodeIndex,
}, },
math::Circle, math::Circle,

View File

@ -6,7 +6,7 @@
mod geometry; mod geometry;
pub mod compound; pub mod compound;
pub mod edit; pub mod edit;
pub mod poly; mod poly;
pub mod primitive; pub mod primitive;
pub mod recording_with_rtree; pub mod recording_with_rtree;
pub mod shape; pub mod shape;

View File

@ -8,16 +8,11 @@ use rstar::AABB;
use crate::geometry::shape::{AccessShape, MeasureLength}; use crate::geometry::shape::{AccessShape, MeasureLength};
#[derive(Debug, Clone, PartialEq)] impl MeasureLength for Polygon {
pub struct PolyShape {
pub polygon: Polygon,
}
impl MeasureLength for PolyShape {
fn length(&self) -> f64 { fn length(&self) -> f64 {
let mut length = 0.0; let mut length = 0.0;
for line in self.polygon.exterior().lines() { for line in self.exterior().lines() {
length += line.length::<Euclidean>(); length += line.length::<Euclidean>();
} }
@ -25,19 +20,18 @@ impl MeasureLength for PolyShape {
} }
} }
impl AccessShape for PolyShape { impl AccessShape for Polygon {
fn center(&self) -> Point { fn center(&self) -> Point {
self.polygon.centroid().unwrap() self.centroid().unwrap()
} }
fn contains_point(&self, p: Point) -> bool { fn contains_point(&self, p: Point) -> bool {
self.polygon.contains(&p) self.contains(&p)
} }
fn bbox_without_margin(&self) -> AABB<[f64; 2]> { fn bbox_without_margin(&self) -> AABB<[f64; 2]> {
AABB::from_points( AABB::from_points(
self.polygon self.exterior()
.exterior()
.0 .0
.iter() .iter()
.map(|coord| [coord.x, coord.y]) .map(|coord| [coord.x, coord.y])

View File

@ -166,10 +166,7 @@ impl AccessShape for SegShape {
} }
fn bbox_without_margin(&self) -> AABB<[f64; 2]> { fn bbox_without_margin(&self) -> AABB<[f64; 2]> {
super::poly::PolyShape { self.polygon().bbox_without_margin()
polygon: self.polygon(),
}
.bbox_without_margin()
} }
} }

View File

@ -3,13 +3,10 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use enum_dispatch::enum_dispatch; use enum_dispatch::enum_dispatch;
use geo::Point; use geo::{Point, Polygon};
use rstar::AABB; use rstar::AABB;
use crate::geometry::{ use crate::geometry::primitive::{BendShape, DotShape, PrimitiveShape, SegShape};
poly::PolyShape,
primitive::{BendShape, DotShape, PrimitiveShape, SegShape},
};
#[enum_dispatch] #[enum_dispatch]
pub trait MeasureLength { pub trait MeasureLength {
@ -37,7 +34,7 @@ pub enum Shape {
Dot(DotShape), Dot(DotShape),
Seg(SegShape), Seg(SegShape),
Bend(BendShape), Bend(BendShape),
Poly(PolyShape), Poly(Polygon),
} }
impl From<PrimitiveShape> for Shape { impl From<PrimitiveShape> for Shape {

View File

@ -27,7 +27,7 @@ use crate::{
geometry::{edit::ApplyGeometryEdit, shape::Shape, GenericNode}, geometry::{edit::ApplyGeometryEdit, shape::Shape, GenericNode},
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetPetgraphIndex},
layout::{ layout::{
poly::{MakePolyShape, Poly, PolyWeight}, poly::{MakePolygon, Poly, PolyWeight},
via::{Via, ViaWeight}, via::{Via, ViaWeight},
}, },
}; };

View File

@ -16,14 +16,14 @@ use crate::{
rules::AccessRules, rules::AccessRules,
seg::SegIndex, seg::SegIndex,
}, },
geometry::{poly::PolyShape, GetPos}, geometry::GetPos,
graph::{GenericIndex, GetPetgraphIndex}, graph::{GenericIndex, GetPetgraphIndex},
layout::{CompoundWeight, Layout}, layout::{CompoundWeight, Layout},
}; };
#[enum_dispatch] #[enum_dispatch]
pub trait MakePolyShape { pub trait MakePolygon {
fn shape(&self) -> PolyShape; fn shape(&self) -> Polygon;
} }
#[enum_dispatch] #[enum_dispatch]
@ -75,10 +75,9 @@ impl<'a, R: AccessRules> GetMaybeNet for Poly<'a, R> {
} }
} }
impl<'a, R: AccessRules> MakePolyShape for Poly<'a, R> { impl<'a, R: AccessRules> MakePolygon for Poly<'a, R> {
fn shape(&self) -> PolyShape { fn shape(&self) -> Polygon {
PolyShape { Polygon::new(
polygon: Polygon::new(
LineString::from( LineString::from(
self.layout self.layout
.drawing() .drawing()
@ -104,8 +103,7 @@ impl<'a, R: AccessRules> MakePolyShape for Poly<'a, R> {
.collect::<Vec<Point>>(), .collect::<Vec<Point>>(),
), ),
vec![], vec![],
), )
}
} }
} }