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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! Utility functions to help with serialization, transformation, and other tasks
//!
//!
use crateResult;
use crateFailedConversion;
use ;
/// Converts a slice of arrays of floating point values into a vector of points with the specified
/// dimensionality.
///
/// # Arguments
///
/// * `slice`: the slice of [f64; D] arrays of floating point values to be converted
///
/// returns: Vec<OPoint<f64, Const<{ D }>>, Global>
///
/// # Examples
///
/// ```
/// use engeom::Point2;
/// use engeom::utility::slice_to_points;
/// let slice = vec![[0.0, 0.5], [1.0, 1.5], [2.0, 2.5]];
/// let points = slice_to_points(&slice);
/// assert_eq!(points.len(), 3);
/// assert_eq!(points[0], Point2::new(0.0, 0.5));
/// assert_eq!(points[1], Point2::new(1.0, 1.5));
/// assert_eq!(points[2], Point2::new(2.0, 2.5));
/// ```
/// Converts a slice of arrays of floating point values into a vector of vectors with the specified
/// dimensionality.
///
/// # Arguments
///
/// * `slice`: the slice of [f64; D] arrays of floating point values to be converted
///
/// returns: Vec<Matrix<f64, Const<{ D }>, Const<1>, ArrayStorage<f64, { D }, 1>>, Global>
///
/// # Examples
///
/// ```
/// use engeom::Vector2;
/// use engeom::utility::slice_to_vectors;
/// let slice = vec![[0.0, 0.5], [1.0, 1.5], [2.0, 2.5]];
/// let vectors = slice_to_vectors(&slice);
/// assert_eq!(vectors.len(), 3);
/// assert_eq!(vectors[0], Vector2::new(0.0, 0.5));
/// assert_eq!(vectors[1], Vector2::new(1.0, 1.5));
/// assert_eq!(vectors[2], Vector2::new(2.0, 2.5));
/// ```
/// Takes a slice of floating point values and returns a vector of points with the specified
/// dimensionality. The number of values must be a multiple of the dimensionality, otherwise an
/// `InvalidCount` error will be returned.
///
/// # Arguments
///
/// * `values`: the slice of floating point values to be unflattened, must be a multiple of `D`
///
/// returns: Result<Vec<OPoint<f64, Const<{ D }>>, Global>, Box<dyn Error, Global>>
///
/// # Examples
///
/// ```
/// use engeom::Point2;
/// use engeom::utility::unflatten_points;
/// let values = vec![0.0, 0.5, 1.0, 1.5, 2.0, 2.5];
/// let points = unflatten_points::<2>(&values).unwrap();
///
/// assert_eq!(points.len(), 3);
/// assert_eq!(points[0], Point2::new(0.0, 0.5));
/// assert_eq!(points[1], Point2::new(1.0, 1.5));
/// assert_eq!(points[2], Point2::new(2.0, 2.5));
/// ```
/// Takes a slice of floating point values and returns a `Vec` of vectors with the specified
/// dimensionality. The number of values must be a multiple of the dimensionality, otherwise an
/// `InvalidCount` error will be returned.
///
/// # Arguments
///
/// * `values`: the slice of floating point values to be unflattened, must be a multiple of `D`
///
/// returns: Result<Vec<Matrix<f64, Const<{ D }>, Const<1>, ArrayStorage<f64, { D }, 1>>, Global>, Box<dyn Error, Global>>
///
/// # Examples
///
/// ```
/// use engeom::Vector2;
/// use engeom::utility::unflatten_vectors;
/// let values = vec![0.0, 0.5, 1.0, 1.5, 2.0, 2.5];
/// let points = unflatten_vectors::<2>(&values).unwrap();
///
/// assert_eq!(points.len(), 3);
/// assert_eq!(points[0], Vector2::new(0.0, 0.5));
/// assert_eq!(points[1], Vector2::new(1.0, 1.5));
/// assert_eq!(points[2], Vector2::new(2.0, 2.5));
/// ```
/// Flattens a slice of points into a vector of floating point values.
///
/// # Arguments
///
/// * `points`: the slice of points to be flattened
///
/// returns: Vec<f64, Global>
///
/// # Examples
///
/// ```
/// use engeom::Point2;
/// use engeom::utility::flatten_points;
/// let points = vec![Point2::new(0.0, 0.5), Point2::new(1.0, 1.5), Point2::new(2.0, 2.5)];
/// let values = flatten_points(&points);
///
/// assert_eq!(values, vec![0.0, 0.5, 1.0, 1.5, 2.0, 2.5]);
/// ```
/// Flattens a slice of vectors into a vec of floating point values.
///
/// # Arguments
///
/// * `points`: the slice of vectors to be flattened
///
/// returns: Vec<f64, Global>
///
/// # Examples
///
/// ```
/// use engeom::Vector2;
/// use engeom::utility::flatten_vectors;
/// let vectors = vec![Vector2::new(0.0, 0.5), Vector2::new(1.0, 1.5), Vector2::new(2.0, 2.5)];
/// let values = flatten_vectors(&vectors);
///
/// assert_eq!(values, vec![0.0, 0.5, 1.0, 1.5, 2.0, 2.5]);
/// ```