Skip to content

Commit 76dd01c

Browse files
Merge pull request #107 from busstoptaktik/work
Completion(?) of CoordinateSet and CoordinateTuple
2 parents bdd0473 + 3c1dce4 commit 76dd01c

File tree

4 files changed

+227
-255
lines changed

4 files changed

+227
-255
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- CoordinateSet: xyz(), set_xyz(), xyzt(), set_xyzt() methods
13+
1214
### Changed
1315

1416
### Removed
1517

18+
- CHANGES.md
19+
1620
## [0.13.0] - 2024-04-06
1721

1822
### Added
@@ -61,7 +65,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6165
- CHANGELOG file (can still be generated by `just changelog`, but not
6266
tracked by git anymore)
6367

64-
6568
## [0.12.0] Release notes
6669

6770
### Improvements

CHANGES.md

-66
This file was deleted.

src/coordinate/mod.rs

+39-5
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ pub trait CoordinateSet: CoordinateMetadata {
129129
/// Number of coordinate tuples in the set
130130
fn len(&self) -> usize;
131131

132-
/// Native dimension of the underlying coordinates (they will always be returned as converted to [`Coor4D`](super::Coor4D))
132+
/// Native dimension of the underlying coordinates (they will always be
133+
/// returned by [`Self::get_coord()`] as converted to [`Coor4D`](super::Coor4D))
133134
fn dim(&self) -> usize;
134135

135136
/// Access the `index`th coordinate tuple
@@ -147,22 +148,55 @@ pub trait CoordinateSet: CoordinateMetadata {
147148
/// with `x` and `y`.
148149
/// Consider providing a type specific version, when implementing
149150
/// the CoordinateSet trait for a concrete data type: The default
150-
/// version is straightforward, but not very efficient.
151+
/// version is straightforward, but not necessarily efficient
151152
fn set_xy(&mut self, index: usize, x: f64, y: f64) {
152153
let mut coord = self.get_coord(index);
153-
coord.set_nth_unchecked(0, x);
154-
coord.set_nth_unchecked(1, y);
154+
coord[0] = x;
155+
coord[1] = y;
155156
self.set_coord(index, &coord);
156157
}
157158

158159
/// Access the two first elements of the `index`th `CoordinateTuple`.
159160
/// Consider providing a type specific version, when implementing
160161
/// the CoordinateSet trait for a concrete data type: The default
161-
/// version is straightforward, but not very efficient.
162+
/// version is straightforward, but not necessarily efficient
162163
fn xy(&self, index: usize) -> (f64, f64) {
163164
self.get_coord(index).xy()
164165
}
165166

167+
/// Replace the three first elements of the `index`th `CoordinateTuple`
168+
/// with `x`, `y` and `z`.
169+
/// Consider providing a type specific version, when implementing
170+
/// the CoordinateSet trait for a concrete data type: The default
171+
/// version is straightforward, but not necessarily efficient
172+
fn set_xyz(&mut self, index: usize, x: f64, y: f64, z: f64) {
173+
let mut coord = self.get_coord(index);
174+
coord[0] = x;
175+
coord[1] = y;
176+
coord[2] = z;
177+
self.set_coord(index, &coord);
178+
}
179+
180+
/// Access the three first elements of the `index`th `CoordinateTuple`.
181+
/// Consider providing a type specific version, when implementing
182+
/// the CoordinateSet trait for a concrete data type: The default
183+
/// version is straightforward, but not necessarily efficient
184+
fn xyz(&self, index: usize) -> (f64, f64, f64) {
185+
self.get_coord(index).xyz()
186+
}
187+
188+
/// Replace the four elements of the `index`th `CoordinateTuple`
189+
/// with `x`, `y`, `z` and `t`. Syntactic sugar for [`Self::set_coord`]
190+
fn set_xyzt(&mut self, index: usize, x: f64, y: f64, z: f64, t: f64) {
191+
self.set_coord(index, &Coor4D([x, y, z, t]));
192+
}
193+
194+
/// Access the four elements of the `index`th `CoordinateTuple`.
195+
/// Syntactic sugar for [`Self::get_coord`]
196+
fn xyzt(&self, index: usize) -> (f64, f64, f64, f64) {
197+
self.get_coord(index).xyzt()
198+
}
199+
166200
/// Set all coordinate tuples in the set to NaN
167201
fn stomp(&mut self) {
168202
let nanny = Coor4D::nan();

0 commit comments

Comments
 (0)