mirror of https://codeberg.org/topola/topola.git
Add method to check if polygon contains point
This commit is contained in:
parent
2fc3b25fec
commit
7aed12dda9
|
|
@ -25,7 +25,7 @@ impl<T: Copy> From<Vector2<T>> for [T; 2] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the point (px, py) is inside the polygon using the ray-casting
|
// Check if the point (px, py) is inside a polygon using the ray-casting
|
||||||
// algorithm.
|
// algorithm.
|
||||||
macro_rules! impl_inside_polygon {
|
macro_rules! impl_inside_polygon {
|
||||||
($type:ty) => {
|
($type:ty) => {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ use rstar::{AABB, Envelope, primitives::Rectangle};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Vector2,
|
||||||
layout::{NetId, PinId},
|
layout::{NetId, PinId},
|
||||||
selection::PinSelector,
|
selection::PinSelector,
|
||||||
Vector2,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|
@ -152,18 +152,18 @@ pub struct Polygon {
|
||||||
|
|
||||||
impl Polygon {
|
impl Polygon {
|
||||||
pub fn bbox(&self) -> Rectangle<[i64; 3]> {
|
pub fn bbox(&self) -> Rectangle<[i64; 3]> {
|
||||||
Rectangle::from_aabb(self.vertices.clone().into_iter().fold(
|
Rectangle::from_aabb(
|
||||||
AABB::new_empty(),
|
self.vertices
|
||||||
|aabb, vertex| {
|
.clone()
|
||||||
aabb.merged(&AABB::from_point([vertex.x, vertex.y, self.layer as i64]))
|
.into_iter()
|
||||||
},
|
.fold(AABB::new_empty(), |aabb, vertex| {
|
||||||
))
|
aabb.merged(&AABB::from_point([vertex.x, vertex.y, self.layer as i64]))
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains_point(&self, point: Vector2<i64>) -> bool {
|
pub fn contains_point(&self, point: Vector2<i64>) -> bool {
|
||||||
/*Vector2::from(point)
|
point.inside_polygon(&self.vertices)
|
||||||
.inside_polygon(&self.vertices.iter().map(Into::into).collect::<Vec<_>>())*/
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pin_selector(&self) -> Option<PinSelector> {
|
pub fn pin_selector(&self) -> Option<PinSelector> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue