From b50bf5d49c0832472ae989f453495131a5c0d3fd Mon Sep 17 00:00:00 2001 From: Lionel Sambuc Date: Fri, 15 Nov 2019 16:01:44 +0100 Subject: [PATCH] Allow clipping shapes when projecting in a space This enables filter() without a collection to work correctly. --- src/database/space/axis.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/database/space/axis.rs b/src/database/space/axis.rs index d31b00c..856ca99 100644 --- a/src/database/space/axis.rs +++ b/src/database/space/axis.rs @@ -160,22 +160,30 @@ impl Axis { let d = position.dot_product(&self.unit_vector); // Apply Unit scaling - let d = d / self.measurement_unit.factor(); + let mut d = d / self.measurement_unit.factor(); // Ensure it is within allowed range: Upper bound. if d > max { - return Err(format!( - "project_in: position out of bounds: {} >= {}", - d, max - )); + // FIXME: Should we generate an error instead? + //return Err(format!( + // "project_in: position out of bounds: {} >= {}", + // d, max + //)); + + // FIXME: For now, just clip. + d = max; } // Ensure it is within allowed range: Lower bound. if d < min { - return Err(format!( - "project_in: position out of bounds: {} < {}", - d, min - )); + // FIXME: Should we generate an error instead? + //return Err(format!( + // "project_in: position out of bounds: {} < {}", + // d, min + //)); + + // FIXME: For now, just clip. + d = min; } self.encode(d)