rustfmt
This commit is contained in:
parent
5bb70ee2f8
commit
e90f9fd6b4
3 changed files with 136 additions and 67 deletions
113
src/main.rs
113
src/main.rs
|
@ -1,12 +1,12 @@
|
|||
use std::ops::Deref;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use constants::*;
|
||||
use nalgebra::Vector3;
|
||||
use scad::*;
|
||||
use constants::*;
|
||||
use selig::Span;
|
||||
use selig::SeligFile;
|
||||
use selig::Point;
|
||||
use selig::SeligFile;
|
||||
use selig::Span;
|
||||
use std::ops::Range;
|
||||
mod constants;
|
||||
mod selig;
|
||||
|
@ -21,8 +21,18 @@ fn main() {
|
|||
|
||||
// cambered airfoil, used in the wing
|
||||
let wing_airfoil: SeligFile = SeligFile::parse(include_str!("../ag24.dat"));
|
||||
println!("name {}, perim {}", wing_airfoil.get_name(), wing_airfoil.get_points().length());
|
||||
println!("desc {}", wing_airfoil.get_description().clone().unwrap_or("no desc".to_string()));
|
||||
println!(
|
||||
"name {}, perim {}",
|
||||
wing_airfoil.get_name(),
|
||||
wing_airfoil.get_points().length()
|
||||
);
|
||||
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));
|
||||
|
||||
let points = wing_airfoil.get_points()[0..80].to_vec();
|
||||
|
@ -39,8 +49,21 @@ fn main() {
|
|||
// struts
|
||||
let mut symetric_spar = scad!(Union);
|
||||
for port in [true, false] {
|
||||
let mut wing = wing(&wing_airfoil, STRUTS/2, WINGSPAN/2.0, CHORD, CHORD * WING_TAPER, SparType::Top);
|
||||
let top_spar = topwing_spar(&wing_airfoil, STRUTS/2, WINGSPAN/2.0, CHORD, CHORD * WING_TAPER);
|
||||
let mut wing = wing(
|
||||
&wing_airfoil,
|
||||
STRUTS / 2,
|
||||
WINGSPAN / 2.0,
|
||||
CHORD,
|
||||
CHORD * WING_TAPER,
|
||||
SparType::Top,
|
||||
);
|
||||
let top_spar = topwing_spar(
|
||||
&wing_airfoil,
|
||||
STRUTS / 2,
|
||||
WINGSPAN / 2.0,
|
||||
CHORD,
|
||||
CHORD * WING_TAPER,
|
||||
);
|
||||
|
||||
let mut top_spar_neg = scad!(Difference; top_spar);
|
||||
top_spar_neg.add_child(wing.clone());
|
||||
|
@ -57,22 +80,29 @@ fn main() {
|
|||
}
|
||||
|
||||
// fuselage affixment point
|
||||
symetric_spar.add_child(centered_cube(vec3(CHORD, FUSELAGE_GAP*2.0, 1.0), (false,true,false)));
|
||||
symetric_spar.add_child(centered_cube(
|
||||
vec3(CHORD, FUSELAGE_GAP * 2.0, 1.0),
|
||||
(false, true, false),
|
||||
));
|
||||
wing_transform.add_child(symetric_spar.clone());
|
||||
register_part(scad!(Projection(false); symetric_spar));
|
||||
|
||||
|
||||
|
||||
// spars
|
||||
|
||||
// "fuselage"
|
||||
scad_file.add_object(scad!(Rotate(-90.0, vec3(0.0, 0.0, 1.0));
|
||||
spar(LENGTH, false))
|
||||
);
|
||||
spar(LENGTH, false)));
|
||||
|
||||
// rudder
|
||||
let mut rudder = scad!(Rotate(90.0, vec3(1.0, 0.0, 0.0)));
|
||||
rudder.add_child(wing(&control_airfoil, RUDDER_STRUTS, RUDDER_HEIGHT, RUDDER_CHORD, RUDDER_CHORD * RUDDER_TAPER, SparType::Center));
|
||||
rudder.add_child(wing(
|
||||
&control_airfoil,
|
||||
RUDDER_STRUTS,
|
||||
RUDDER_HEIGHT,
|
||||
RUDDER_CHORD,
|
||||
RUDDER_CHORD * RUDDER_TAPER,
|
||||
SparType::Center,
|
||||
));
|
||||
rudder.add_child(spar(RUDDER_HEIGHT, false));
|
||||
rudder = scad!(Translate(vec3(LENGTH-RUDDER_CHORD, 0.0, 0.0)); rudder);
|
||||
scad_file.add_object(rudder);
|
||||
|
@ -81,8 +111,21 @@ fn main() {
|
|||
let mut elevator = scad!(Translate(vec3(LENGTH - ELEVATOR_CHORD, 0.0, 0.0)));
|
||||
let mut symetric_spar = scad!(Union);
|
||||
for port in [true, false] {
|
||||
let mut wing = wing(&wing_airfoil, ELEVATOR_STRUTS, ELEVATOR_HEIGHT, ELEVATOR_CHORD, ELEVATOR_CHORD * ELEVATOR_TAPER, SparType::Top);
|
||||
let top_spar = topwing_spar(&wing_airfoil, ELEVATOR_STRUTS, ELEVATOR_HEIGHT, ELEVATOR_CHORD, ELEVATOR_CHORD * ELEVATOR_TAPER);
|
||||
let mut wing = wing(
|
||||
&wing_airfoil,
|
||||
ELEVATOR_STRUTS,
|
||||
ELEVATOR_HEIGHT,
|
||||
ELEVATOR_CHORD,
|
||||
ELEVATOR_CHORD * ELEVATOR_TAPER,
|
||||
SparType::Top,
|
||||
);
|
||||
let top_spar = topwing_spar(
|
||||
&wing_airfoil,
|
||||
ELEVATOR_STRUTS,
|
||||
ELEVATOR_HEIGHT,
|
||||
ELEVATOR_CHORD,
|
||||
ELEVATOR_CHORD * ELEVATOR_TAPER,
|
||||
);
|
||||
let mut top_spar_neg = scad!(Difference; top_spar);
|
||||
top_spar_neg.add_child(wing.clone());
|
||||
symetric_spar.add_child(top_spar_neg.clone());
|
||||
|
@ -94,10 +137,12 @@ fn main() {
|
|||
}
|
||||
scad_file.add_object(elevator);
|
||||
|
||||
symetric_spar.add_child(centered_cube(vec3(CHORD, FUSELAGE_GAP*2.0, 1.0), (false,true,false)));
|
||||
symetric_spar.add_child(centered_cube(
|
||||
vec3(CHORD, FUSELAGE_GAP * 2.0, 1.0),
|
||||
(false, true, false),
|
||||
));
|
||||
register_part(scad!(Projection(false); symetric_spar));
|
||||
|
||||
|
||||
let cardboard = vec3(0.38, 0.26, 0.26);
|
||||
scad_file.add_object(scad!(Color(cardboard); wing_transform));
|
||||
|
||||
|
@ -134,7 +179,7 @@ fn strut(airfoil: &SeligFile, chord: f32, width: f32, spar: &SparType) -> ScadOb
|
|||
SparType::Top => topspar_negative(airfoil, chord, 0.1..0.6),
|
||||
SparType::Center => {
|
||||
scad!(Union)
|
||||
},
|
||||
}
|
||||
SparType::None => {
|
||||
scad!(Union)
|
||||
}
|
||||
|
@ -144,7 +189,13 @@ fn strut(airfoil: &SeligFile, chord: f32, width: f32, spar: &SparType) -> ScadOb
|
|||
extrude_strut(shape, strut_hole, width, chord, true)
|
||||
}
|
||||
|
||||
fn extrude_strut(shape: ScadObject, strut_hole: ScadObject, width: f32, chord: f32, register:bool) -> ScadObject {
|
||||
fn extrude_strut(
|
||||
shape: ScadObject,
|
||||
strut_hole: ScadObject,
|
||||
width: f32,
|
||||
chord: f32,
|
||||
register: bool,
|
||||
) -> ScadObject {
|
||||
let mut strut_shape = scad!(Difference);
|
||||
strut_shape.add_child(shape);
|
||||
strut_shape.add_child(strut_hole);
|
||||
|
@ -172,7 +223,9 @@ fn topspar_negative(airfoil: &SeligFile, chord: f32, range: Range<f32>) -> ScadO
|
|||
let points = &points[0..points.len() / 2];
|
||||
let perimeter = span_length(points);
|
||||
|
||||
let span = points.to_vec().points_in_range(perimeter * (1.0-range.end) .. perimeter * (1.0-range.start));
|
||||
let span = points
|
||||
.to_vec()
|
||||
.points_in_range(perimeter * (1.0 - range.end)..perimeter * (1.0 - range.start));
|
||||
|
||||
let mut mask = scad!(Union);
|
||||
|
||||
|
@ -219,12 +272,18 @@ fn lerp(a: f32, b:f32, x:f32) -> f32 {
|
|||
a * (1.0 - x) + b * x
|
||||
}
|
||||
|
||||
fn wing(aerofoil: &SeligFile, 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
|
||||
for strut_idx in 0..struts + 1 {
|
||||
|
||||
let gap = length / struts as f32;
|
||||
|
||||
let chord = lerp(chord, taper, strut_idx as f32 / struts as f32);
|
||||
|
@ -241,7 +300,13 @@ fn wing(aerofoil: &SeligFile, struts: usize, length: f32, chord: f32, taper: f32
|
|||
wing
|
||||
}
|
||||
|
||||
fn topwing_spar(aerofoil: &SeligFile, 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<ScadObject> = None;
|
||||
|
@ -249,7 +314,6 @@ fn topwing_spar(aerofoil: &SeligFile, struts: usize, length: f32, chord: f32, ta
|
|||
|
||||
// struts
|
||||
for strut_idx in 0..struts + 1 {
|
||||
|
||||
let gap = length / struts as f32;
|
||||
|
||||
let chord = lerp(chord, taper, strut_idx as f32 / struts as f32);
|
||||
|
@ -262,7 +326,6 @@ fn topwing_spar(aerofoil: &SeligFile, struts: usize, length: f32, chord: f32, ta
|
|||
let mut transform = scad!(Translate(vec3(0.0, spacing, 0.0)));
|
||||
transform.add_child(extruded);
|
||||
|
||||
|
||||
// in betweens
|
||||
if let Some(last) = last_segment {
|
||||
let mut hull = scad!(Hull);
|
||||
|
|
36
src/selig.rs
36
src/selig.rs
|
@ -1,7 +1,4 @@
|
|||
use std::ops::Range;
|
||||
use std::ops::RangeFull;
|
||||
use std::ops::Deref;
|
||||
use std::ops::Index;
|
||||
|
||||
use nalgebra::Vector2;
|
||||
|
||||
|
@ -19,7 +16,11 @@ impl SeligFile {
|
|||
let mut points = Vec::new();
|
||||
|
||||
let mut lines = file.lines();
|
||||
let mut header = lines.next().expect("selig .dat is empty").split(" | ").map(|x| x.trim());
|
||||
let mut header = lines
|
||||
.next()
|
||||
.expect("selig .dat is empty")
|
||||
.split(" | ")
|
||||
.map(|x| x.trim());
|
||||
let name = header.next().unwrap().to_string();
|
||||
let description = header.next().map(|d| d.to_string());
|
||||
|
||||
|
@ -32,7 +33,7 @@ impl SeligFile {
|
|||
SeligFile {
|
||||
name,
|
||||
description,
|
||||
data: points
|
||||
data: points,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +48,6 @@ impl SeligFile {
|
|||
pub fn get_description(&self) -> &Option<String> {
|
||||
&self.description
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub trait Span {
|
||||
|
@ -79,21 +79,27 @@ impl Span for Airfoil {
|
|||
for point in self {
|
||||
if let Some(last) = last_point {
|
||||
let span: f32 = (last - point).magnitude();
|
||||
match (range.contains(&distance), range.contains(&(distance+span))) {
|
||||
(true, true) => { // fully within span
|
||||
match (
|
||||
range.contains(&distance),
|
||||
range.contains(&(distance + span)),
|
||||
) {
|
||||
(true, true) => {
|
||||
// fully within span
|
||||
points.push(point.clone());
|
||||
},
|
||||
(false, true) => { // entering span
|
||||
}
|
||||
(false, true) => {
|
||||
// entering span
|
||||
let undershoot = distance - range.start;
|
||||
let part_out = (span - undershoot) / span;
|
||||
points.push(last.lerp(&point, part_out));
|
||||
},
|
||||
(true, false) => { // exiting span
|
||||
}
|
||||
(true, false) => {
|
||||
// exiting span
|
||||
let overshoot = range.end - distance;
|
||||
let part_in = (span - overshoot) / span;
|
||||
points.push(last.lerp(&point, part_in));
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
distance += span;
|
||||
}
|
||||
|
@ -105,7 +111,7 @@ impl Span for Airfoil {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Span, SeligFile};
|
||||
use super::{SeligFile, Span};
|
||||
|
||||
#[test]
|
||||
fn full_perimiter() {
|
||||
|
|
Loading…
Reference in a new issue