shape,layout: restore and fix bend-seg collision detection

This commit is contained in:
Mikolaj Wielgus 2024-02-08 18:11:34 +00:00
parent 7fdf90b126
commit b66995b30c
4 changed files with 36 additions and 11 deletions

View File

@ -120,8 +120,8 @@ impl ShapeTrait for SegShape {
match other {
Shape::Dot(..) => unreachable!(),
Shape::Seg(other) => self.polygon().intersects(&other.polygon()),
Shape::Bend(_other) => {
/*for segment in self.polygon().exterior().lines() {
Shape::Bend(other) => {
for segment in self.polygon().exterior().lines() {
let inner_circle = other.inner_circle();
let outer_circle = other.outer_circle();
@ -136,7 +136,7 @@ impl ShapeTrait for SegShape {
return true;
}
}
}*/
}
false
}

View File

@ -24,6 +24,7 @@ use crate::layout::geometry::{
SegWeightTrait,
};
use crate::layout::guide::Guide;
use crate::layout::primitive::GetLimbs;
use crate::layout::rules::{Conditions, GetConditions};
use crate::layout::{
bend::{FixedBendIndex, LooseBendIndex, LooseBendWeight},
@ -852,6 +853,14 @@ impl<R: RulesTrait> Layout<R> {
let old_pos = self.geometry_with_rtree.geometry().dot_weight(dot).pos();
self.geometry_with_rtree.move_dot(dot, to);
for limb in dot.primitive(self).limbs() {
if let Some(infringement) = self.detect_infringement_except(limb.into(), infringables) {
// Restore original state.
self.geometry_with_rtree.move_dot(dot, old_pos);
return Err(infringement);
}
}
if let Some(infringement) = self.detect_infringement_except(dot.into(), infringables) {
// Restore original state.
self.geometry_with_rtree.move_dot(dot, old_pos);

View File

@ -523,8 +523,8 @@ fn main() -> Result<(), anyhow::Error> {
dot_start,
dot_end,
3.0,
&mut EmptyRouterObserver,
//&mut DebugRouterObserver::new(&mut event_pump, &window, &mut renderer, &font_context),
//&mut EmptyRouterObserver,
&mut DebugRouterObserver::new(&mut event_pump, &window, &mut renderer, &font_context),
)?;
render_times(

View File

@ -191,14 +191,30 @@ pub fn intersect_circle_segment(circle: &Circle, segment: &Line) -> Vec<Point> {
}
if discriminant == 0.0 {
return [from + (to - from) * -b / (2.0 * a)].into();
let u = -b / (2.0 * a);
if u >= 0.0 && u <= 1.0 {
return [from + (to - from) * -b / (2.0 * a)].into();
} else {
return [].into();
}
}
[
from + (to - from) * (-b + discriminant.sqrt()) / (2.0 * a),
from + (to - from) * (-b - discriminant.sqrt()) / (2.0 * a),
]
.into()
let mut v = vec![];
let u1 = (-b + discriminant.sqrt()) / (2.0 * a);
if u1 >= 0.0 && u1 <= 1.0 {
v.push(from + (to - from) * u1);
}
let u2 = (-b - discriminant.sqrt()) / (2.0 * a);
if u2 >= 0.0 && u2 <= 1.0 {
v.push(from + (to - from) * u2);
}
v
}
pub fn between_vectors(p: Point, from: Point, to: Point) -> bool {