egui: fix painted bend direction

This commit is contained in:
Mikolaj Wielgus 2024-06-25 00:39:31 +02:00
parent 1706d5ae8c
commit b35e6fc66a
2 changed files with 11 additions and 5 deletions

View File

@ -1,7 +1,7 @@
use geo::{CoordsIter, Point, Polygon}; use geo::{CoordsIter, Point, Polygon};
use topola::{ use topola::{
geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait}, geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait},
math::Circle, math::{self, Circle},
}; };
pub struct Painter<'a> { pub struct Painter<'a> {
@ -31,12 +31,14 @@ impl<'a> Painter<'a> {
let delta_to = bend.to - bend.c.pos; let delta_to = bend.to - bend.c.pos;
let angle_from = delta_from.y().atan2(delta_from.x()); let angle_from = delta_from.y().atan2(delta_from.x());
let angle_to = delta_to.y().atan2(delta_to.x());
let cross = math::cross_product(delta_from, delta_to);
let dot = math::dot_product(delta_from, delta_to);
let angle_step = cross.atan2(dot) / 100.0;
let mut points: Vec<egui::Pos2> = vec![]; let mut points: Vec<egui::Pos2> = vec![];
let angle_step = (angle_to - angle_from) / 100.0; for i in 0..=100 {
for i in 0..100 {
let x = bend.c.pos.x() + bend.c.r * (angle_from + i as f64 * angle_step).cos(); let x = bend.c.pos.x() + bend.c.r * (angle_from + i as f64 * angle_step).cos();
let y = bend.c.pos.y() + bend.c.r * (angle_from + i as f64 * angle_step).sin(); let y = bend.c.pos.y() + bend.c.r * (angle_from + i as f64 * angle_step).sin();
points.push(self.transform.transform_pos([x as f32, -y as f32].into())); points.push(self.transform.transform_pos([x as f32, -y as f32].into()));

View File

@ -238,6 +238,10 @@ pub fn seq_cross_product(start: Point, stop: Point, reference: Point) -> f64 {
cross_product((dx1, dy1).into(), (dx2, dy2).into()) cross_product((dx1, dy1).into(), (dx2, dy2).into())
} }
pub fn dot_product(v1: Point, v2: Point) -> f64 {
v1.x() * v2.x() + v1.y() * v2.y()
}
pub fn cross_product(v1: Point, v2: Point) -> f64 { pub fn cross_product(v1: Point, v2: Point) -> f64 {
v1.x() * v2.y() - v1.y() * v2.x() v1.x() * v2.y() - v1.y() * v2.x()
} }