From c49a3ea241fdf83fd0ed2a36b85d421b4b1bdd9d Mon Sep 17 00:00:00 2001 From: numzero Date: Fri, 28 Jun 2024 14:54:00 +0300 Subject: [PATCH] Test for the bugfix --- src/bin/flat/tube/mod.rs | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/bin/flat/tube/mod.rs b/src/bin/flat/tube/mod.rs index 28f7357..ba970ed 100644 --- a/src/bin/flat/tube/mod.rs +++ b/src/bin/flat/tube/mod.rs @@ -296,4 +296,58 @@ mod coords { } } } + + #[cfg(test)] + mod test { + use super::{Location, Tube, MapperOuter}; + use glam::{Mat2, vec2}; + use itertools_num::linspace; + + #[test] + fn test_mapper_outer() { + let mapper = Tube { + inner_radius: 30.0, + outer_radius: 50.0, + internal_halflength: 100.0, + external_halflength: 300.0, + }; + // straight + for x in linspace(-60., 60., 20) { + for y in linspace(-320., 320., 20) { + assert_eq!(mapper.global_to_outer(Location { pos: vec2(x, y), rot: Mat2::IDENTITY }).pos.x, x); + } + } + // symmetrical + for x in linspace(0., 60., 20) { + for y in linspace(0., 320., 20) { + let pp = mapper.global_to_outer(Location { pos: vec2(x, y), rot: Mat2::IDENTITY }).pos; + let np = mapper.global_to_outer(Location { pos: vec2(-x, y), rot: Mat2::IDENTITY }).pos; + let pn = mapper.global_to_outer(Location { pos: vec2(x, -y), rot: Mat2::IDENTITY }).pos; + let nn = mapper.global_to_outer(Location { pos: vec2(-x, -y), rot: Mat2::IDENTITY }).pos; + assert_eq!(np, vec2(-pp.x, pp.y)); + assert_eq!(pn, vec2(pp.x, -pp.y)); + assert_eq!(nn, vec2(-pp.x, -pp.y)); + } + } + // clean boundary + for x in linspace(50., 60., 20) { + for y in linspace(0., 320., 20) { + assert_eq!(mapper.global_to_outer(Location { pos: vec2(x, y), rot: Mat2::IDENTITY }).pos.y, y); + } + } + for x in linspace(0., 60., 20) { + for y in linspace(300., 320., 20) { + assert_eq!(mapper.global_to_outer(Location { pos: vec2(x, y), rot: Mat2::IDENTITY }).pos.y, y); + } + } + // accelerating + for x in linspace(-29., 29., 20) { + for y in linspace(1., 299., 20) { + let v = mapper.global_to_outer(Location { pos: vec2(x, y), rot: Mat2::IDENTITY }).pos.y; + assert!(v > 200.0); + assert!(v > y); + } + } + } + } }