-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1364 from hannobraun/template
Embed model template in `fj-app` directory, use it to generate model
- Loading branch information
Showing
7 changed files
with
62 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "model-template" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies.fj] | ||
path = "../../fj" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Fornjot - Model Template | ||
|
||
This template is compiled into the `fj-app` binary, where it is used to generate new models. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::f64::consts::PI; | ||
|
||
#[fj::model] | ||
pub fn model( | ||
#[param(default = 5, min = 3)] num_points: u64, | ||
#[param(default = 1.0, min = 1.0)] r1: f64, | ||
#[param(default = 2.0, min = 2.0)] r2: f64, | ||
#[param(default = 1.0)] h: f64, | ||
) -> fj::Shape { | ||
let num_vertices = num_points * 2; | ||
let vertex_iter = (0..num_vertices).map(|i| { | ||
let angle = | ||
fj::Angle::from_rad(2. * PI / num_vertices as f64 * i as f64); | ||
let radius = if i % 2 == 0 { r1 } else { r2 }; | ||
(angle, radius) | ||
}); | ||
|
||
// Now that we got that iterator prepared, generating the vertices is just a | ||
// bit of trigonometry. | ||
let mut outer = Vec::new(); | ||
let mut inner = Vec::new(); | ||
for (angle, radius) in vertex_iter { | ||
let (sin, cos) = angle.rad().sin_cos(); | ||
|
||
let x = cos * radius; | ||
let y = sin * radius; | ||
|
||
outer.push([x, y]); | ||
inner.push([x / 2., y / 2.]); | ||
} | ||
|
||
let outer = fj::Sketch::from_points(outer); | ||
let inner = fj::Sketch::from_points(inner); | ||
|
||
let footprint = fj::Difference2d::from_shapes([outer.into(), inner.into()]); | ||
|
||
let star = fj::Sweep::from_path(footprint.into(), [0., 0., h]); | ||
|
||
star.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters