use togo::prelude::*;
const ZERO: f64 = 0.0;
pub fn pline_01() -> Vec<Polyline> {
let pline = vec![
pvertex(point(100.0, 100.0), 1.5),
pvertex(point(100.0, 160.0), ZERO),
pvertex(point(120.0, 200.0), ZERO),
pvertex(point(128.0, 192.0), ZERO),
pvertex(point(128.0, 205.0), ZERO),
pvertex(point(136.0, 197.0), ZERO),
pvertex(point(136.0, 245.0), -1.0), pvertex(point(131.0, 250.0), ZERO),
pvertex(point(110.0, 250.0), -1.0), pvertex(point(78.0, 250.0), ZERO),
pvertex(point(50.0, 250.0), -1.0), pvertex(point(38.0, 250.0), ZERO),
pvertex(point(0.001, 250.0), 100000.0), pvertex(point(0.0, 250.0), ZERO),
pvertex(point(-52.0, 250.0), ZERO),
pvertex(
point(-23.429621235520095, 204.88318696736243),
-0.6068148963145962,
),
pvertex(point(82.0, 150.0), 0f64),
pvertex(point(50.0, 150.0), 1.0),
pvertex(point(-20.0, 150.0), ZERO),
pvertex(point(0.0, 100.0), ZERO),
];
let pline2 = polyline_scale(&pline, 1.0);
let plines = vec![pline2.clone()];
return plines;
}
pub fn pline_02() -> Polyline {
let pline = vec![
pvertex(point(50.0, 50.0), ZERO),
pvertex(point(200.0, 50.0), ZERO),
pvertex(point(180.0, 55.0), ZERO),
pvertex(point(160.0, 65.0), ZERO),
pvertex(point(140.0, 80.0), ZERO),
pvertex(point(120.0, 100.0), ZERO),
pvertex(point(100.0, 125.0), ZERO),
pvertex(point(120.0, 150.0), ZERO),
pvertex(point(140.0, 170.0), ZERO),
pvertex(point(160.0, 185.0), ZERO),
pvertex(point(180.0, 195.0), ZERO),
pvertex(point(200.0, 200.0), ZERO),
pvertex(point(-50.0, 200.0), ZERO),
pvertex(point(-30.0, 195.0), ZERO),
pvertex(point(-10.0, 185.0), ZERO),
pvertex(point(10.0, 170.0), ZERO),
pvertex(point(30.0, 150.0), ZERO),
pvertex(point(50.0, 125.0), ZERO),
pvertex(point(30.0, 100.0), ZERO),
pvertex(point(10.0, 80.0), ZERO),
pvertex(point(-10.0, 65.0), ZERO),
pvertex(point(-30.0, 55.0), ZERO),
pvertex(point(-50.0, 50.0), ZERO),
pvertex(point(50.0, 50.0), ZERO),
];
return pline;
}
pub fn pline_03() -> Vec<Polyline> {
let pline = vec![
pvertex(point(0.0, 0.0), ZERO),
pvertex(point(200.0, 0.0), ZERO),
pvertex(point(200.0, 100.0), ZERO),
pvertex(point(100.0, 100.0), ZERO),
pvertex(point(100.0, 200.0), ZERO),
pvertex(point(0.0, 200.0), ZERO),
];
let pline2 = polyline_scale(&pline, 1.0);
let plines = vec![pline2.clone()];
return plines;
}
pub fn pline_04() -> Vec<Polyline> {
let outer = vec![
pvertex(point(50.0, 50.0), 0.2),
pvertex(point(100.0, 50.0), -0.5),
pvertex(point(100.0, 100.0), 0.2),
pvertex(point(50.0, 100.0), -0.5),
];
let inner = vec![
pvertex(point(75.0, 60.0), ZERO),
pvertex(point(80.0, 75.0), ZERO),
pvertex(point(75.0, 80.0), ZERO),
pvertex(point(70.0, 75.0), ZERO),
];
let inner = polyline_reverse(&inner);
let mut plines = Vec::new();
plines.push(outer);
plines.push(inner);
return plines;
}
pub fn pline_500() -> Polyline {
let center = Point::new(250.0, 250.0);
let root_radius = 80.0; let tip_radius = 150.0; let num_teeth = 6; let points_per_tooth = 83;
let mut vertices = Vec::new();
for tooth_num in 0..num_teeth {
let tooth_center_angle = (tooth_num as f64) * 2.0 * std::f64::consts::PI / (num_teeth as f64);
let tooth_width = 2.0 * std::f64::consts::PI / (num_teeth as f64);
for i in 0..points_per_tooth {
let t = (i as f64) / ((points_per_tooth - 1) as f64);
let angle_offset = if t < 0.1 || t > 0.9 {
let base_phase = if t < 0.1 {
t / 0.1 } else {
(1.0 - t) / 0.1 };
(base_phase * std::f64::consts::PI).sin() * 0.1 * tooth_width
} else {
(t - 0.5) * tooth_width
};
let angle = tooth_center_angle + angle_offset;
let radius = if t < 0.2 {
root_radius + (tip_radius - root_radius) * (t / 0.2)
} else if t < 0.3 {
tip_radius - (tip_radius - root_radius) * 0.05 * ((t - 0.2) / 0.1)
} else if t < 0.7 {
tip_radius
} else if t < 0.8 {
tip_radius - (tip_radius - root_radius) * 0.05 * ((t - 0.7) / 0.1)
} else {
tip_radius - (tip_radius - root_radius) * ((t - 0.8) / 0.2)
};
let point = Point::new(
center.x + radius * angle.cos(),
center.y + radius * angle.sin(),
);
let bulge = if t < 0.33 {
let local_t = t / 0.33;
let strength = 1.0 - local_t * local_t;
let base_bulge = 0.7 * strength;
if ((t * 10.0) as i32) % 2 == 0 {
base_bulge
} else {
-base_bulge * 0.4
}
} else if t < 0.67 {
let local_t = (t - 0.33) / 0.34;
let strength = 0.3 + 0.7 * (1.0 - local_t.powi(2));
let base_bulge = 0.7 * strength;
if ((t * 10.0) as i32) % 2 == 0 {
base_bulge
} else {
-base_bulge * 0.4
}
} else {
let local_t = (t - 0.67) / 0.33;
let strength = 1.0 - local_t * local_t;
let base_bulge = -0.7 * strength;
if ((t * 10.0) as i32) % 2 == 0 {
base_bulge
} else {
-base_bulge * 0.4
}
};
vertices.push(pvertex(point, bulge));
}
}
if let Some(first) = vertices.first() {
vertices.push(*first);
}
vertices
}