extrude_catenary/
extrude_catenary.rs

1// Copyright 2025 Jordan Johnson
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4use lib_curveball::curve::CurveResult;
5use lib_curveball::curve::extrude::path::Catenary;
6use lib_curveball::curve::extrude::profile::{Anchor9Point, Rectangle};
7use lib_curveball::curve::extrude::{ProfileOrientation, ProfilePlane, extrude};
8use lib_curveball::map::{
9    entity::SimpleWorldspawn,
10    geometry::Brush,
11    qmap::{QEntity, QMap},
12};
13
14fn brushes_to_string(brushes: Vec<Brush>) -> CurveResult<String> {
15    let simple_worldspawn = SimpleWorldspawn::new(brushes);
16    let entity = QEntity::from(simple_worldspawn);
17    let map = QMap::new(vec![entity]).with_tb_neverball_metadata();
18    Ok(String::from(format!("{map}")))
19}
20
21fn main() {
22    // Create the rectangle profile
23    let width = 32.0;
24    let height = 8.0;
25    let anchor = Anchor9Point::Center;
26    let rectangle_profile = Rectangle::new(width, height, anchor).unwrap();
27
28    // Create the catenary path
29    let span = 128.0;
30    let height = 0.0;
31    let s = 132.0;
32    let catenary_path = Catenary::new(span, height, s).unwrap();
33
34    // Extrude to create the path
35    let num_segments = 12;
36    let profile_orientation = ProfileOrientation::Constant(ProfilePlane::YZ);
37    let brushes = extrude(
38        num_segments,
39        &rectangle_profile,
40        &catenary_path,
41        profile_orientation,
42    )
43    .unwrap();
44
45    // Print the map out
46    let string = brushes_to_string(brushes).unwrap();
47    println!("{}", string);
48}