Add last() on SpaceFillingCurve

This commit is contained in:
2019-10-21 14:43:55 +02:00
parent b0635d05d7
commit ad52da09b7
2 changed files with 23 additions and 24 deletions

View File

@@ -223,27 +223,18 @@ where
space
}
/*
pub fn cells_id(&self, position: &Vec<V>) -> Result<Vec<Option<usize>>, String> {
trace!("cells_id: position {:?}", position);
//TODO: Should we check inside each objects, or just assume it is correct and/or rely on the bound checks?
if self.dimensions != position.len() {
return Err(format!(
"Incorrect number of dimensions, expected {}, got {} for {:?}",
self.dimensions,
position.len(),
position
));
}
let mut cells = vec![];
for k in 0..self.dimensions {
cells.push(self.coordinates[k].cell_id(&position[k]));
}
trace!("cells_id: cells {:?}", cells);
Ok(cells)
pub fn last(&self) -> (Vec<usize>, Vec<usize>) {
let mut cells = Vec::with_capacity(self.dimensions);
let mut offsets = Vec::with_capacity(self.dimensions);
for k in 0..self.dimensions {
let (cell_id, offset) = self.coordinates[k].last();
cells.push(cell_id);
offsets.push(offset);
}
*/
(cells, offsets)
}
pub fn key(&self, position: &K) -> Result<(Vec<usize>, Vec<usize>), String> {
//TODO: Should we check inside each objects, or just assume it is correct and/or rely on the bound checks?
/* This impose to require ExactSizeIterator, which is not implemented on Vec, and can't be in any easy way.

View File

@@ -172,16 +172,24 @@ where
self.morton.encode(&t)
}
// Build coordinate values from encoded value
fn position(&self, code: SFCCode, offsets: &[SFCOffset]) -> Result<K, String> {
let position = self.space.value(
fn last(&self) -> (Vec<usize>, Vec<usize>) {
self.space.last()
}
fn value(&self, code: SFCCode, offsets: &[SFCOffset]) -> Result<Vec<&V>, String> {
Ok(self.space.value(
self.morton
.decode(code)
.iter()
.map(|e| *e as usize)
.collect(),
offsets.iter().map(|e| *e as usize).collect(),
)?;
)?)
}
// Build coordinate values from encoded value
fn position(&self, code: SFCCode, offsets: &[SFCOffset]) -> Result<K, String> {
let position = self.value(code, offsets)?;
Ok(position.iter().map(|i| (*i).clone()).collect())
}