From d221f8640b153d337b167bec36924fb6d0023832 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sat, 4 Nov 2023 06:32:37 -0500 Subject: [PATCH] refactor --- src/main.rs | 16 +++++++--------- src/selig.rs | 16 ++++++++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7d83d80..74f723f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::sync::Mutex; use nalgebra::Vector3; use scad::*; use constants::*; -use selig::Airfoil; +use selig::SeligFile; use selig::Point; use std::ops::Range; mod constants; @@ -18,7 +18,7 @@ fn main() { scad_file.set_detail(50); // cambered airfoil, used in the wing - let wing_airfoil: Airfoil = Airfoil::parse(include_str!("../ag24.dat")); + let wing_airfoil: SeligFile = SeligFile::parse(include_str!("../ag24.dat")); println!("name {}, perim {}", wing_airfoil.get_name(), wing_airfoil.perimiter()); println!("desc {}", wing_airfoil.get_description().clone().unwrap_or("no desc".to_string())); //println!("span {:?}", points_in_range(wing_airfoil.get_points()[0..80], 0.0..1.0)); @@ -30,7 +30,7 @@ fn main() { register_part(scad!(Polygon(points))); // symetric airfoil, used in the control surfaces - let control_airfoil: Airfoil = Airfoil::parse(include_str!("../edgevertical.dat")); + let control_airfoil: SeligFile = SeligFile::parse(include_str!("../edgevertical.dat")); let mut wing_transform = scad!(Translate(vec3(0.0,0.0,0.0))); @@ -123,7 +123,7 @@ enum SparType { } /// returns a extruded airfoil with the given dimensions -fn strut(airfoil: &Airfoil, chord: f32, width: f32, spar: &SparType) -> ScadObject { +fn strut(airfoil: &SeligFile, chord: f32, width: f32, spar: &SparType) -> ScadObject { let aerofoil = scad::PolygonParameters::new(airfoil.get_points().clone()); let shape = scad!(Polygon(aerofoil)); @@ -165,7 +165,7 @@ fn extrude_strut(shape: ScadObject, strut_hole: ScadObject, width: f32, chord: f rotated } -fn topspar_negative(airfoil: &Airfoil, chord: f32, range: Range) -> ScadObject { +fn topspar_negative(airfoil: &SeligFile, chord: f32, range: Range) -> ScadObject { let points = airfoil.get_points(); let points = &points[0.. points.len() / 2]; let perimeter = span_length(points); @@ -217,7 +217,7 @@ fn lerp(a: f32, b:f32, x:f32) -> f32 { a*(1.0-x) + b*x } -fn wing(aerofoil: &Airfoil, struts: usize, length: f32, chord: f32, taper: f32, spar: SparType) -> ScadObject { +fn wing(aerofoil: &SeligFile, struts: usize, length: f32, chord: f32, taper: f32, spar: SparType) -> ScadObject { let mut wing = scad!(Translate(vec3(0.0,0.0,0.0))); // struts @@ -239,7 +239,7 @@ fn wing(aerofoil: &Airfoil, struts: usize, length: f32, chord: f32, taper: f32, wing } -fn topwing_spar(aerofoil: &Airfoil, struts: usize, length: f32, chord: f32, taper: f32) -> ScadObject { +fn topwing_spar(aerofoil: &SeligFile, struts: usize, length: f32, chord: f32, taper: f32) -> ScadObject { let mut wing = scad!(Hull); let mut last_segment : Option = None; @@ -298,13 +298,11 @@ pub fn points_in_range(input: &Vec, range: Range) -> Vec { match (range.contains(&distance), range.contains(&(distance+span))) { (true, true) => { // fully within span points.push(point.clone()); - println!("in {span}"); }, (false, true) => { // entering span let undershoot = distance - range.start; let part_out = (span - undershoot) / span; points.push(last.lerp(&point, part_out)); - println!("enter"); }, (true, false) => { // exiting span let overshoot = range.end - distance; diff --git a/src/selig.rs b/src/selig.rs index f66235c..87e7eb1 100644 --- a/src/selig.rs +++ b/src/selig.rs @@ -3,15 +3,16 @@ use std::ops::Range; use nalgebra::Vector2; pub type Point = Vector2; +pub type Airfoil = Vec; -pub struct Airfoil { +pub struct SeligFile { name: String, description: Option, - data: Vec, + data: Airfoil, } -impl Airfoil { - pub fn parse(file: &str) -> Airfoil { +impl SeligFile { + pub fn parse(file: &str) -> SeligFile { let mut points = Vec::new(); let mut lines = file.lines(); @@ -25,14 +26,14 @@ impl Airfoil { let y = numbers.next().unwrap().parse().unwrap(); points.push(Point::new(x,y)) } - Airfoil { + SeligFile { name, description, data: points } } - pub fn get_points(&self) -> &Vec { + pub fn get_points(&self) -> &Airfoil { &self.data } @@ -44,6 +45,9 @@ impl Airfoil { &self.description } +} + +impl Airfoil { pub fn perimiter(&self) -> f32 { self.span_length(&self.get_points()[..]) }