Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HANDOFF.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ It started on 2026-10-13 as "WinterMiles" (an icTrainer alternative for riding G
| **Trainers and sensors** | Protocols unit-tested against the specs. The first real trainer — a **Tacx Vortex Smart (T2180) over Bluetooth** — connected but **kept dropping out and showed no power**. Not yet diagnosed: a diagnostics report from a ride is needed. This is the top priority. |
| **Virtual gears** | The maths is unit-tested and shifting was checked with the demo rider and the smoke harness (`VP_SMOKE_SHIFT`), but it has **never been felt on a real trainer**. |
| **OpenBikeControl controllers** | Button decoding and the choice of one action per press are unit-tested; never connected to a real controller. |
| **Herne Hill Velodrome** | Built-in track. The route is in `crates/core/src/velodrome.rs`; the banked track, its paint and the buildings are in `world/venue.rs`. Tested in code, and I've checked a live preview in demo mode on both renderers, each way round (`VP_SMOKE_ROUTE=herne-hill` or `herne-hill-clockwise`). Nobody has ridden it with a trainer yet. |
| **Laps on loop routes** | Lap engine, bests, segments and renderers unit-tested in `crates/core`; smoke-run across the line on Linux with three.js, not yet with the native renderer (macOS). Group standings don't show who is a lap up. |
| **Strava** (OAuth, upload, segments, activities as ghosts) | Never run against the live API. Users must create their own API key (open source can't ship a secret). Scope is `read,activity:read_all,activity:write`. |
| **Windows and Linux** | Built and packaged by CI on every push (and Arch's package is installed in a container and its libraries checked), but **never run by a person**. |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Free and open source ([GPLv3](LICENSE)) for **Windows, macOS and Linux**. Writte
- **GPX in, virtual ride out.** Import routes from Strava, Komoot, RideWithGPS or a bike computer. Routes with no elevation data (planner exports) get it filled in automatically.
- **A 3D version of the real place.** The road follows your GPX; the surrounding landscape is built from open elevation data, so the mountains on the horizon are the real ones. OpenStreetMap supplies the rest: the towns and villages you pass through, forests where the real forests are, lakes, rivers and streams, the side roads, lanes, footpaths and railways around you, and the bridges and tunnels of the real road — you ride over the river on a bridge deck, into the hillside through a lit tunnel, and under the motorway or railway that crosses overhead. A live OpenStreetMap minimap and a gradient-coloured elevation profile sit alongside. Works offline with generated hills.
- **Laps.** On a closed route, ride it once, for 2, 3, 5, 10 or 20 laps, or until you stop. The HUD counts the laps and the distance ridden, and the profile, landmarks and riders carry on across the line.
- **Herne Hill Velodrome, built in.** The 450 m outdoor track in south London where the 1948 Olympic track events were raced, at its real place: banked to 26° in the bends, painted with the côte d'azur and the sprinters' and stayers' lines, and ringed by the railing and floodlights, with the 2018 pavilion, the bleachers, the club's containers and canopy, and the junior track in the middle. Ride it anticlockwise as raced, or clockwise. It is the same track as OpenBikeNet's `herne-hill-450` route.
- **A closed road, race-day style.** The road you ride is set apart from the map's road network: steel crowd barriers line both sides (with banners on some, each section standing on its feet and leaning with the road on hills, and orange netting round the outside of tight hairpins instead), its surface is the real one — tarmac, concrete slabs, cobbles, gravel or dirt — and so is its width: a 7 m main road, a 5 m village street, a 3 m farm track. Both come from OpenStreetMap's tags for the roads along the route (`surface`, `width`, `lanes`, and the road class), or are guessed from the road class when those can't be fetched. Where the route leaves the mapped roads for 100 m or more — across a field, along an unmapped trail — it becomes a dirt track. Widths change gradually, and buildings, signs, other riders and the barriers all follow them. Ride the Arenberg trench on its setts and the Strade Bianche on white gravel — and feel them: rougher surfaces roll heavier, so you slow down on screen and the trainer gets harder.
- **Mountain-bike trails.** Where the route follows an unpaved path, a bridleway, a walking trail or a trail graded for mountain bikes (OpenStreetMap's `mtb:scale`, S0–S6, or estimated from the hiking grade), you ride a narrow earth singletrack with no barriers, the HUD shows the grade, and the harder the grade the heavier it rolls — on screen and on the trainer.
- **Find a route in the app.** Search for a place, click waypoints on the map and get a route along bike-friendly roads with real elevation (BRouter), or pick one of eight famous climbs (Alpe d'Huez, Mont Ventoux, Stelvio, Galibier, Tourmalet, Mortirolo, Zoncolan, Box Hill). Mountain bikers can plan along trails, or pick from the **waymarked MTB routes** mapped in the area on screen.
Expand Down Expand Up @@ -70,6 +71,7 @@ Be aware of what has and has not been proven:
| Waymarked MTB routes | Listed and joined from the live Overpass API around Finale Ligure (a 23 km route joined with no gaps); the joining is unit-tested. The screen itself was only type-checked, not clicked through |
| Strava segments and ghosts from Strava | Matching is unit-tested; the Strava calls have **not** been made against the live API |
| Street-level photos | Selection unit-tested and a bad token is reported correctly; not tried with a real Mapillary token |
| Herne Hill Velodrome | Tested in code: a lap is 450 m from the line, the bends bank to 26°, the ground is level, and it works both ways round. Checked a live preview in demo mode on both renderers, riding each direction. Not yet ridden with a trainer. The buildings are sized from the map and photos, so they're close to the real ones but not exact |
| Native renderer | Screenshots from the automated run match the built-in renderer (day, dusk with rain fog, high camera, the leaning barriers and tree sprites of 0.3.6, and the hedge banks of 0.3.7). The HUD on top of it was not checked in a screenshot of the real window |
| FIT export | Unit-tested by decoding the output with an independent FIT parser |
| Bluetooth and ANT+ **protocol** encoding/decoding (FTMS, Cycling Power, CSC, HR, ANT framing, ANT+ HR/power/speed/cadence/FE-C pages) | Unit-tested against hand-built packets |
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod physics;
pub mod ride;
pub mod segments;
pub mod types;
pub mod velodrome;
pub mod waymarked;
pub mod workout;
pub mod world;
149 changes: 149 additions & 0 deletions crates/core/src/velodrome.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//! Velodromes: real cycling tracks built into the app as routes, ridden in laps.
//!
//! A track is an oval of two straights and two semicircles round its measuring line, placed
//! at its real location. Its route is the measuring line itself, so a lap is the track's
//! official length; the world round it (the banked track, its markings, the stands) is drawn
//! by `world::venue`. Herne Hill's oval is the one in OpenBikeNet's `herne-hill-450` route
//! file (fitted to the track's outline in OpenStreetMap), so riders from other apps line up.

use crate::gpx::{build_route_with_step, RawPoint, Route, M_PER_DEG};

/// A track's shape and place.
#[derive(Debug, Clone, Copy)]
pub struct Track {
/// Route ID for riding it anticlockwise, as track races go; `<id>-clockwise` the other way.
pub id: &'static str,
pub name: &'static str,
/// One lap on the measuring line, in metres.
pub length: f64,
/// Radius of the bends on the measuring line.
pub radius: f64,
/// The middle of the oval, as (lat, lon).
pub centre: (f64, f64),
/// Direction of the long axis, in degrees anticlockwise from east.
pub axis: f64,
/// The start/finish line is this far from the middle of the home straight, against the
/// direction of riding anticlockwise.
pub start_offset: f64,
/// The riding surface from inside edge to outside edge, côte d'azur included.
pub width: f64,
/// Banking at the steepest part of the bends, and along the straights, in degrees.
pub bend_banking: f64,
pub straight_banking: f64,
}

/// Herne Hill Velodrome, London: opened in 1891, the track events of the 1948 Olympics, 450 m.
/// Sources give its banking as anything from 18° to 30°; 26° (the 1992 rebuild) has the most behind it.
pub const HERNE_HILL: Track = Track {
id: "herne-hill",
name: "Herne Hill Velodrome",
length: 450.0,
radius: 45.3,
centre: (51.45105, -0.09142),
axis: -76.8,
start_offset: 13.0,
width: 7.4,
bend_banking: 26.0,
straight_banking: 7.0,
};

pub const TRACKS: [Track; 1] = [HERNE_HILL];

/// Points along the bends, about this far apart.
const BEND_STEP: f64 = 2.5;
/// The route is sampled this often, in metres (roads are every 5 m).
pub const ROUTE_STEP: f64 = 1.0;

impl Track {
/// Length of each straight on the measuring line.
pub fn straight(&self) -> f64 {
(self.length - 2.0 * std::f64::consts::PI * self.radius) / 2.0
}

/// The route ID for riding it this way round.
pub fn route_id(&self, clockwise: bool) -> String {
if clockwise {
format!("{}-clockwise", self.id)
} else {
self.id.to_string()
}
}

pub fn route_name(&self, clockwise: bool) -> String {
if clockwise {
format!("{} (clockwise)", self.name)
} else {
self.name.to_string()
}
}

/// The measuring line as `(a, b)` metres from the middle of the oval, `a` along the long
/// axis and `b` across it, the home straight at `b = +radius`: from the start/finish line
/// round anticlockwise and back to it.
pub fn outline(&self) -> Vec<(f64, f64)> {
let (r, half) = (self.radius, self.straight() / 2.0);
let steps = (std::f64::consts::PI * r / BEND_STEP).round() as usize;
let mut points = vec![(-self.start_offset, r), (-half, r)];
for k in 1..steps {
let t = std::f64::consts::FRAC_PI_2 + std::f64::consts::PI * k as f64 / steps as f64;
points.push((-half + r * t.cos(), r * t.sin()));
}
points.extend([(-half, -r), (half, -r)]);
for k in 1..steps {
let t = -std::f64::consts::FRAC_PI_2 + std::f64::consts::PI * k as f64 / steps as f64;
points.push((half + r * t.cos(), r * t.sin()));
}
points.push((half, r));
points.push(points[0]);
points
}

/// `(a, b)` metres in the oval's frame as (lat, lon), stretched by `scale`.
fn lat_lon(&self, (a, b): (f64, f64), scale: f64) -> (f64, f64) {
let (c, s) = (self.axis.to_radians().cos(), self.axis.to_radians().sin());
let (east, north) = ((a * c - b * s) * scale, (a * s + b * c) * scale);
(self.centre.0 + north / M_PER_DEG, self.centre.1 + east / (M_PER_DEG * self.centre.0.to_radians().cos()))
}

/// The route: the measuring line at its real place, flat, exactly `length` round (as the
/// app measures distance), from the start/finish line and back. Sampled every metre, so the
/// bends are smooth and rounding off corners takes nothing measurable off a lap.
pub fn route(&self, clockwise: bool) -> Route {
let outline = self.outline();
let build = |scale: f64| {
let mut points: Vec<RawPoint> = outline
.iter()
.map(|&q| {
let (lat, lon) = self.lat_lon(q, scale);
RawPoint { lat, lon, ele: Some(0.0) }
})
.collect();
if clockwise {
points.reverse();
}
build_route_with_step(&self.route_name(clockwise), &points, ROUTE_STEP).expect("a track is a valid route")
};
// Scaled until the route as built, smoothing and all, is the track's length.
let first: f64 = outline.windows(2).map(|w| (w[1].0 - w[0].0).hypot(w[1].1 - w[0].1)).sum();
let mut scale = self.length / first;
let mut route = build(scale);
for _ in 0..3 {
scale *= self.length / route.total;
route = build(scale);
}
route
}
}

/// The track and which way round, for a built-in track's route ID.
pub fn track_for(route_id: &str) -> Option<(Track, bool)> {
TRACKS.iter().find_map(|t| {
if route_id == t.id {
Some((*t, false))
} else if route_id == t.route_id(true) {
Some((*t, true))
} else {
None
}
})
}
4 changes: 4 additions & 0 deletions crates/core/src/world/barriers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ impl World {
/// on the inside of a bend too tight to stand them; round a tight bend, fence panels
/// (look `FENCE`) on the outside instead.
pub fn barriers(&self) -> Vec<[f32; 7]> {
// A velodrome has its own railing.
if self.venue.is_some() {
return Vec::new();
}
let r = &self.route;
let kinds = self.field.kinds();
let blocked = |i: usize| kinds.get(i).is_some_and(|&kind| kind != OPEN) || self.scene.trails.get(i).is_some_and(Option::is_some);
Expand Down
21 changes: 20 additions & 1 deletion crates/core/src/world/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub struct HeightField {
/// For open samples, 1 at a tunnel mouth falling to 0 away from it; for bridge
/// samples, how far the ground must stay below the deck.
shape: Vec<f32>,
/// Grounds laid level, such as a velodrome's: the ground there is at their height.
grounds: Option<super::venue::Grounds>,
}

impl HeightField {
Expand Down Expand Up @@ -165,7 +167,7 @@ impl HeightField {
_ => 0.0,
})
.collect();
Self { route, dem, dem_offset, grid, coarse, lattice: Mutex::new(HashMap::new()), mean_ele, kinds, shape }
Self { route, dem, dem_offset, grid, coarse, lattice: Mutex::new(HashMap::new()), mean_ele, kinds, shape, grounds: None }
}

pub fn kinds(&self) -> &[u8] {
Expand Down Expand Up @@ -253,7 +255,24 @@ impl HeightField {
(p.surface, p.road)
}

/// Lays the ground level over `grounds`, blending back into the land round them.
pub(super) fn set_grounds(&mut self, grounds: super::venue::Grounds) {
self.grounds = Some(grounds);
}

pub fn probe(&self, x: f64, z: f64, roughness: f64) -> Probe {
let mut p = self.probe_land(x, z, roughness);
if let Some(g) = &self.grounds {
let level = g.levelled(x, z);
if level > 0.0 && !p.trench {
p.ground = mix(p.ground, g.height, level);
p.surface = p.ground;
}
}
p
}

fn probe_land(&self, x: f64, z: f64, roughness: f64) -> Probe {
let route = &self.route;
let (cx, cz) = (cell(x, HASH_CELL), cell(z, HASH_CELL));
// Per kind of road: inverse-distance weights, weighted elevation, and the nearest sample.
Expand Down
Loading
Loading