-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1030 from hannobraun/validate
Clean up validation code
- Loading branch information
Showing
14 changed files
with
167 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::fmt; | ||
|
||
use fj_math::{Point, Scalar}; | ||
|
||
use crate::objects::Vertex; | ||
|
||
pub fn validate_vertex( | ||
vertex: &Vertex, | ||
max_distance: impl Into<Scalar>, | ||
) -> Result<(), CoherenceMismatch> { | ||
let max_distance = max_distance.into(); | ||
|
||
// Validate that the local and global forms of the vertex match. As a side | ||
// effect, this also happens to validate that the global form of the vertex | ||
// lies on the curve. | ||
|
||
let local = vertex.position(); | ||
let local_as_global = vertex | ||
.curve() | ||
.global() | ||
.kind() | ||
.point_from_curve_coords(local); | ||
let global = vertex.global().position(); | ||
let distance = (local_as_global - global).magnitude(); | ||
|
||
if distance > max_distance { | ||
return Err(CoherenceMismatch { | ||
local, | ||
local_as_global, | ||
global, | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// A mismatch between the local and global forms of an object | ||
#[derive(Debug, Default, thiserror::Error)] | ||
pub struct CoherenceMismatch { | ||
/// The local form of the object | ||
pub local: Point<1>, | ||
|
||
/// The local form of the object, converted into the global form | ||
pub local_as_global: Point<3>, | ||
|
||
/// The global form of the object | ||
pub global: Point<3>, | ||
} | ||
|
||
impl fmt::Display for CoherenceMismatch { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!( | ||
f, | ||
"local: {:?} (converted to global: {:?}), global: {:?},", | ||
self.local, self.local_as_global, self.global, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,4 +91,3 @@ pub mod algorithms; | |
pub mod builder; | ||
pub mod iter; | ||
pub mod objects; | ||
pub mod validation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.