mirror of https://codeberg.org/topola/topola.git
fix(math/bitangents): Calculate bitangents even for intersecting circles
This fixes the bug where the router was failing to draw around SMD pads.
This commit is contained in:
parent
1ddca4e580
commit
676c24a428
|
|
@ -16,7 +16,7 @@ fn _bitangent(center: Point, r1: f64, r2: f64) -> Result<LineInGeneralForm, ()>
|
||||||
// Taken from https://cp-algorithms.com/geometry/tangents-to-two-circles.html
|
// Taken from https://cp-algorithms.com/geometry/tangents-to-two-circles.html
|
||||||
// with small changes.
|
// with small changes.
|
||||||
|
|
||||||
if approx::relative_eq!(center.x(), 0.0) && approx::relative_eq!(center.y(), 0.0) {
|
if center.x() == 0.0 && center.y() == 0.0 {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ fn _bitangent(center: Point, r1: f64, r2: f64) -> Result<LineInGeneralForm, ()>
|
||||||
let norm = center.x() * center.x() + center.y() * center.y();
|
let norm = center.x() * center.x() + center.y() * center.y();
|
||||||
let discriminant = norm - dr * dr;
|
let discriminant = norm - dr * dr;
|
||||||
|
|
||||||
if discriminant < -epsilon {
|
if discriminant <= -epsilon {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ fn bitangent_point_pairs(
|
||||||
circle1: Circle,
|
circle1: Circle,
|
||||||
circle2: Circle,
|
circle2: Circle,
|
||||||
) -> Result<Vec<(Point, Point)>, NoBitangents> {
|
) -> Result<Vec<(Point, Point)>, NoBitangents> {
|
||||||
let point_pairs: Vec<(Point, Point)> = _bitangents(circle1, circle2)
|
let bitangents: Vec<(Point, Point)> = _bitangents(circle1, circle2)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|tg| {
|
.map(|tg| {
|
||||||
(
|
(
|
||||||
|
|
@ -80,10 +80,11 @@ fn bitangent_point_pairs(
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if point_pairs.is_empty() {
|
if bitangents.is_empty() {
|
||||||
return Err(NoBitangents(circle1, circle2));
|
return Err(NoBitangents(circle1, circle2));
|
||||||
}
|
}
|
||||||
Ok(point_pairs)
|
|
||||||
|
Ok(bitangents)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bitangents(
|
pub fn bitangents(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue