Skip to content

Commit

Permalink
enhance: use circles instead of triangles as heads
Browse files Browse the repository at this point in the history
  • Loading branch information
carrascomj committed Oct 5, 2023
1 parent 9196cdf commit 7bd6834
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
bevy = {version="0.9.1", features = ["bevy_render", "bevy_core_pipeline", "bevy_asset", "bevy_sprite", "render", "bevy_winit", "png", "x11"], default-features=false }
bevy_egui = "0.17.1"
bevy_pancam = { version = "0.7.0", features = ["bevy_egui"] }
bevy_prototype_lyon = "0.7.1"
bevy_prototype_lyon = "0.7.2"
colorgrad = "0.6.2"
itertools = "0.10.5"
fastrand = "1.8.0"
Expand Down
2 changes: 1 addition & 1 deletion src/aesthetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fn build_axes(
transform.translation.y += arrow.direction.perp().y * away;
transform
};
let mut axis_entry = axes
let axis_entry = axes
.entry(arrow.id.clone())
.or_insert(HashMap::new())
.entry(geom.side.clone())
Expand Down
14 changes: 9 additions & 5 deletions src/escher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ pub fn load_map(
let ori: Vec2 = Vec2::new(ori.x, -ori.y);
let direction = my_map.main_direction(&reac);
let mut products = reac.get_products(&my_map.metabolism);
let mut arrow_heads = ShapePath::new();
for (_, segment) in reac.segments.iter_mut() {
if let (Some(from), Some(to)) = (
my_map.met_coords(&segment.from_node_id),
Expand Down Expand Up @@ -480,10 +481,11 @@ pub fn load_map(
if let Some((drawn, importance)) = products.get_mut(&segment.to_node_id) {
if !*drawn {
let offset = match importance {
MetImportance::Primary => 20.0,
MetImportance::Secondary => 12.0,
MetImportance::Primary => 22.0,
MetImportance::Secondary => 14.0,
};
draw_arrow(&mut path_builder, last_from - ori, re_to - ori, offset);
arrow_heads =
arrow_heads.add(&draw_arrow(last_from - ori, re_to - ori, offset));
*drawn = true;
}
}
Expand All @@ -501,9 +503,11 @@ pub fn load_map(
node_id,
xlimits: None,
};
let mut builder = GeometryBuilder::new();
builder = builder.add(&line);
builder = builder.add(&arrow_heads.build());
commands.spawn((
GeometryBuilder::build_as(
&line,
builder.build(
DrawMode::Stroke(StrokeMode::new(ARROW_COLOR, 10.0)),
Transform::from_xyz(ori.x - center_x, ori.y + center_y, 1.),
),
Expand Down
23 changes: 6 additions & 17 deletions src/funcplot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy::prelude::{Color, Font, Handle, Text, Text2dBundle, TextStyle, Transfor
use bevy_prototype_lyon::{
entity::ShapeBundle,
prelude::{DrawMode, GeometryBuilder, Path, PathBuilder, StrokeMode},
shapes,
};
use colorgrad::{Color as GradColor, CustomGradient, Gradient};

Expand Down Expand Up @@ -365,24 +366,12 @@ pub fn build_grad(
.expect("no gradient")
}

fn arrow_head(from: Vec2, to: Vec2) -> (Vec2, Vec2) {
// triangle shape; hardcoded for now
const HEIGHT: f32 = 1.0;
const HALF_W: f32 = 14.0;
let u = (to - from) / (to - from).length();
let v = Vec2::new(-u.y, u.x);
(
(to - HEIGHT * u + HALF_W * v),
(to - HEIGHT * u - HALF_W * v),
)
}

pub fn draw_arrow(path: &mut PathBuilder, from: Vec2, to: Vec2, offset: f32) {
pub fn draw_arrow(from: Vec2, to: Vec2, offset: f32) -> shapes::Circle {
// with an offset to avoid being hidden by metabolites
let u = (to - from) / (to - from).length();
let to = to - offset * u;
let (left, right) = arrow_head(from, to);
path.move_to(right);
// path.line_to(to);
path.line_to(left);
shapes::Circle {
radius: 5.0,
center: to,
}
}
2 changes: 1 addition & 1 deletion src/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn zoom_fonts(
return;
};
for (mut text, def) in text_query.iter_mut() {
for mut section in text.sections.iter_mut() {
for section in text.sections.iter_mut() {
let new_font_size = lerp(proj.scale, 1., 40., def.size, def.size * 10.);
// step update to enhance perfomance
if (new_font_size - section.style.font_size).abs() > 1.0 {
Expand Down

0 comments on commit 7bd6834

Please sign in to comment.