Skip to content

Commit

Permalink
Add markings for multi-gauge track.
Browse files Browse the repository at this point in the history
  • Loading branch information
partim committed Mar 28, 2024
1 parent 8895fda commit 5f2066f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 20 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
<body>
<div id="map" class="map"></div>
<ul id="layers">
<li id="el" onclick="toggleActive('el'); toggleActive('el-lat')">el</li>
<li id="el-lat" onclick="toggleActive('el-lat'); toggleActive('el')">el-lat</li>
<li id="el" onclick="toggleActive('el')">el</li>
<li id="el-lat" onclick="toggleActive('el-lat')">el-lat</li>
<li id="el-num" onclick="toggleActive('el-num')">el-num</li>
<li id="pax" onclick="toggleActive('pax'); toggleActive('pax-lat')">pax</li>
<li id="pax-lat" onclick="toggleActive('pax-lat'); toggleActive('pax')">pax-lat</li>
<li id="pax" onclick="toggleActive('pax')">pax</li>
<li id="pax-lat" onclick="toggleActive('pax-lat')">pax-lat</li>
<li id="pax-num" onclick="toggleActive('pax-num')">pax-num</li>
</ul>
<script type="text/javascript">
Expand Down
43 changes: 40 additions & 3 deletions src/railway/feature/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! * `:inner` if the segment is in the middle and markings need to be
//! “justified.”
use std::f64::consts::FRAC_PI_2;
use std::f64::consts::{FRAC_PI_2, PI};
use femtomap::world;
use femtomap::import::eval::{EvalErrors, Failed, SymbolSet};
use femtomap::path::Trace;
Expand All @@ -45,7 +45,7 @@ use femtomap::render::{
};
use kurbo::{PathEl, Vec2};
use crate::railway::import::eval::{Expression, Scope};
use crate::railway::class::{Railway, Pax};
use crate::railway::class::{GaugeGroup, Railway, Pax};
use crate::railway::style::Style;
use super::{AnyShape, Category, Feature, Shape, Stage};

Expand Down Expand Up @@ -700,16 +700,53 @@ impl<'a> ContourShape4<'a> {
}

fn render_gauge(&self, style: &Style, canvas: &mut Sketch) {
use super::super::class::GaugeGroup::*;
if self.class.class.gauge().secondary().is_some() {
self.render_multi_gauge(style, canvas)
}
else if !matches!(
self.class.class.gauge_group(), GaugeGroup::Standard
) {
self.render_gauge_group(style, canvas)
}
}

fn render_multi_gauge(&self, style: &Style, canvas: &mut Sketch) {
let seg = match self.seg {
Some(seg) => seg,
None => return
};

let radius = style.units().dt * 0.5;
let halfwidth = style.units().guide_width * 0.5;
let inner_radius = radius - halfwidth;
let outer_radius = radius + halfwidth;

self.track.iter_positions(
seg, Some(0.5 * seg)
).for_each(|(pos, dir)| {
canvas.apply(style.track_color(&self.class.class));
canvas.apply(kurbo::Circle::new(pos, outer_radius));
canvas.fill();
canvas.apply(Color::WHITE);
canvas.apply(kurbo::CircleSegment::new(
pos, inner_radius, 0., dir + 0.5 * PI, PI,
));
canvas.fill();
})
}

fn render_gauge_group(&self, style: &Style, canvas: &mut Sketch) {
use super::super::class::GaugeGroup::*;

let group = self.class.class.gauge_group();
if matches!(group, Standard) {
return
};

let seg = match self.seg {
Some(seg) => seg,
None => return
};
let radius = style.units().dt * 0.5;
let width = style.units().guide_width;
let radius_width = radius + 0.5 * width;
Expand Down

0 comments on commit 5f2066f

Please sign in to comment.