draw: Choose the shortest guide tangent

This commit is contained in:
Mikolaj Wielgus 2023-09-05 05:51:21 +02:00
parent 49038a4ddb
commit f88636057f
1 changed files with 38 additions and 23 deletions

View File

@ -81,37 +81,39 @@ impl<'a> Draw<'a> {
pub fn segbend_around_dot(
&mut self,
mut head: Head,
head: Head,
around: DotIndex,
cw: bool,
width: f64,
) -> Result<Head, ()> {
let tangent = self
.guide(&Default::default())
.head_around_dot_segments(&head, around, width)
.1;
/*.into_iter()
.max_by(|x, y| x.euclidean_length().total_cmp(&y.euclidean_length()))
.unwrap();*/
/*let tangents = self
let mut tangents = self
.guide(&Default::default())
.head_around_dot_segments(&head, around, width);
let tangent = if tangents.0.euclidean_length() <= tangents.1.euclidean_length() {
tangents.0
} else {
tangents.1
};*/
if tangents.1.euclidean_length() < tangents.0.euclidean_length() {
tangents = (tangents.1, tangents.0);
}
head = self.extend_head(head, tangent.start_point())?;
self.segbend(
for (i, tangent) in [tangents.0, tangents.1].iter().enumerate() {
match self.segbend_around(
head,
TaggedIndex::Dot(around),
tangent.start_point(),
tangent.end_point(),
cw,
width,
)
) {
Ok(head) => {
return Ok(head);
}
Err(err) => {
if i >= 1 {
return Err(err);
}
}
}
}
unreachable!();
}
pub fn segbend_around_bend(
@ -135,6 +137,19 @@ impl<'a> Draw<'a> {
)
}
fn segbend_around(
&mut self,
mut head: Head,
around: TaggedIndex,
from: Point,
to: Point,
cw: bool,
width: f64,
) -> Result<Head, ()> {
head = self.extend_head(head, from)?;
self.segbend(head, around, to, cw, width)
}
fn extend_head(&mut self, head: Head, to: Point) -> Result<Head, ()> {
if let Some(..) = head.segbend {
self.extend_head_bend(head, to)