1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crate::mesh::{DefaultEdgePayload, DefaultFacePayload, EuclideanMeshType, MeshTrait};
/// A trait for creating plane approximations.
pub trait MakePlane<const D: usize, T: EuclideanMeshType<D, Mesh = Self>>:
MeshTrait<T = T>
where
T::EP: DefaultEdgePayload,
T::FP: DefaultFacePayload,
{
// TODO: requires better theory of edges and half edges
/*
/// Generate a subdivided plane made of triangles with given `width` and `height` and
/// `n` and `m` vertices used for the subdivisions, i.e., to subdivide the plane into
/// four columns, use `n = 5`.
fn triangle_plane(width: T::S, height: T::S, n: usize, m: usize) -> Self {
let mut mesh = Self::default();
let vertical_step = height / T::S::from_usize(m - 1);
let half_horizontal_step = width / T::S::from_usize(n - 1) * T::S::HALF;
let iter = |j: usize| {
(0..n).map(move |i| {
T::VP::from_pos(T::Vec::from_xy(
half_horizontal_step * T::S::from_usize(i * 2 + (j % 2)),
vertical_step * T::S::from_usize(j),
))
})
};
let (mut first, _) = mesh.insert_path(iter(0));
for j in 1..m {
let e = mesh.loft_tri_back(first, j % 2 == 0, iter(j));
first = mesh.edge(e).prev_id();
}
mesh
}*/
/*
/// Generate a subdivided plane made of quads with given `width` and `height` and
/// `n` and `m` vertices used for the subdivisions, i.e., to subdivide the plane into
/// four columns, use `n = 5`.
fn quad_plane(width: T::S, height: T::S, n: usize, m: usize) -> Self {
let mut mesh = Self::default();
let vertical_step = height / T::S::from_usize(m - 1);
let horizontal_step = width / T::S::from_usize(n - 1);
let iter = |j: usize| {
(0..n).map(move |i| {
T::VP::from_pos(T::Vec::from_xy(
horizontal_step * T::S::from_usize(i),
vertical_step * T::S::from_usize(j),
))
})
};
let (mut first, _) = mesh.insert_path(iter(0));
for j in 1..m {
first = mesh.loft_polygon_back(first, 2, 2, iter(j));
}
mesh
}
/// Generate a subdivided plane made of hexagons with `n` and `m` vertices used for the subdivisions.
/// TODO: Make this more quadratic and less parallelogram.
fn hex_plane(n: usize, m: usize) -> Self {
assert!(n % 2 == 0);
assert!(m >= 2);
let mut mesh = Self::default();
let row_height = T::S::THREE / T::S::THREE.sqrt();
let width = T::S::ONE;
let hex_offset = row_height - T::S::TWO / T::S::THREE.sqrt();
let iter = |offset: usize, j: usize| {
(0..n).map(move |i| {
T::VP::from_pos(T::Vec::from_xy(
width * T::S::from_usize(i + offset),
row_height * T::S::from_usize(j)
+ T::S::from_usize((i + j + 1 + offset) % 2) * hex_offset,
))
})
};
let (mut first, _) = mesh.insert_path(iter(0, 0));
for j in 1..m {
if j >= 2 {
first = mesh.edge(first).prev_id();
}
first = mesh.loft_polygon_back(first, 3, 3, iter(j - 1, j));
}
mesh
}*/
}