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},
graph::{GenericIndex, GetPetgraphIndex},
layout::{
poly::{MakePolyShape, PolyWeight},
poly::{MakePolygon, PolyWeight},
via::ViaWeight,
CompoundWeight, Layout, NodeIndex,
},

View File

@ -5,7 +5,10 @@
use geo::{CoordsIter, Point, Polygon};
use rstar::AABB;
use topola::{
geometry::primitive::{AccessPrimitiveShape, PrimitiveShape},
geometry::{
primitive::{AccessPrimitiveShape, PrimitiveShape},
shape::AccessShape,
},
math::Circle,
};
@ -54,7 +57,7 @@ impl<'a> Painter<'a> {
self.ui.painter().add(epaint_shape);
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,
},
geometry::{shape::AccessShape, GenericNode},
layout::{poly::MakePolyShape, via::ViaWeight},
layout::{poly::MakePolygon, via::ViaWeight},
math::Circle,
};
@ -175,10 +175,7 @@ impl Viewport {
.normal
};
painter.paint_polygon(
&board.layout().poly(poly).shape().polygon,
color,
)
painter.paint_polygon(&board.layout().poly(poly).shape(), color)
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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