view_cubic_bezier_chain/view_cubic_bezier_chain.rs
1// MIT License
2//
3// Copyright (c) 2023 Michael H. Phillips
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23//! In this example we use the Viewer struct to visualize a cubic bezier chain.
24//! This example is 2d but the viewer is not limited to 2d. A 3D bezier chain
25//! example would be the same with dim2 changed to dim3, Pt2 changed to Pt3 etc.
26//!
27//! The curve segments will be white with gray points while the control handles
28//! are shown in green.
29
30use scad_tree::prelude::*;
31
32fn main() {
33 let mut curve = dim2::CubicBezierChain2D::new(
34 Pt2::new(0.0, 0.0),
35 Pt2::new(40.0, -20.0),
36 Pt2::new(40.0, 80.0),
37 Pt2::new(0.0, 40.0),
38 24,
39 );
40 curve.add(20.0, Pt2::new(-30.0, 50.0), Pt2::new(-50.0, 40.0), 12);
41
42 let mut viewer = Viewer::new(0.5, 0.25, 6);
43 viewer.add_cubic_bezier_chain2d(&curve);
44 scad_file!(32, "output/view_cubic_bezier_chain.scad",
45 viewer.into_scad();
46 );
47}