mirror of https://codeberg.org/topola/topola.git
draw: Choose the shortest guide tangent
This commit is contained in:
parent
49038a4ddb
commit
f88636057f
61
src/draw.rs
61
src/draw.rs
|
|
@ -81,37 +81,39 @@ impl<'a> Draw<'a> {
|
||||||
|
|
||||||
pub fn segbend_around_dot(
|
pub fn segbend_around_dot(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut head: Head,
|
head: Head,
|
||||||
around: DotIndex,
|
around: DotIndex,
|
||||||
cw: bool,
|
cw: bool,
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<Head, ()> {
|
) -> Result<Head, ()> {
|
||||||
let tangent = self
|
let mut tangents = 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
|
|
||||||
.guide(&Default::default())
|
.guide(&Default::default())
|
||||||
.head_around_dot_segments(&head, around, width);
|
.head_around_dot_segments(&head, around, width);
|
||||||
|
|
||||||
let tangent = if tangents.0.euclidean_length() <= tangents.1.euclidean_length() {
|
if tangents.1.euclidean_length() < tangents.0.euclidean_length() {
|
||||||
tangents.0
|
tangents = (tangents.1, tangents.0);
|
||||||
} else {
|
}
|
||||||
tangents.1
|
|
||||||
};*/
|
|
||||||
|
|
||||||
head = self.extend_head(head, tangent.start_point())?;
|
for (i, tangent) in [tangents.0, tangents.1].iter().enumerate() {
|
||||||
self.segbend(
|
match self.segbend_around(
|
||||||
head,
|
head,
|
||||||
TaggedIndex::Dot(around),
|
TaggedIndex::Dot(around),
|
||||||
tangent.end_point(),
|
tangent.start_point(),
|
||||||
cw,
|
tangent.end_point(),
|
||||||
width,
|
cw,
|
||||||
)
|
width,
|
||||||
|
) {
|
||||||
|
Ok(head) => {
|
||||||
|
return Ok(head);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
if i >= 1 {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn segbend_around_bend(
|
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, ()> {
|
fn extend_head(&mut self, head: Head, to: Point) -> Result<Head, ()> {
|
||||||
if let Some(..) = head.segbend {
|
if let Some(..) = head.segbend {
|
||||||
self.extend_head_bend(head, to)
|
self.extend_head_bend(head, to)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue