Rename minmax functions to bounds

This commit is contained in:
Connor Slade
2025-02-15 12:31:48 -05:00
parent d3bf1e35e1
commit 41f3a49ce2
6 changed files with 11 additions and 11 deletions

View File

@@ -135,7 +135,7 @@ impl App {
mesh.set_scale_unchecked(mesh.scale().component_mul(&mm_to_px));
let (min, max) = mesh.minmax_point();
let (min, max) = mesh.bounds();
preview_scale = preview_scale
.min(self.slice_config.platform_size.x / (max.x - min.x))
.min(self.slice_config.platform_size.y / (max.y - min.y));

View File

@@ -32,7 +32,7 @@ pub fn render_preview_image(
let (mut min, mut max) = (Vector3::repeat(f32::MAX), Vector3::repeat(f32::MIN));
for model in workspace.models.read().iter() {
let (model_min, model_max) = model.mesh.minmax_point();
let (model_min, model_max) = model.mesh.bounds();
min = min.zip_map(&model_min, f32::min);
max = max.zip_map(&model_max, f32::max);
}

View File

@@ -89,7 +89,7 @@ impl RenderedMesh {
}
pub fn align_to_bed(&mut self) {
let (bottom, _) = self.mesh.minmax_point();
let (bottom, _) = self.mesh.bounds();
let pos = self.mesh.position() - Vector3::new(0.0, 0.0, bottom.z);
self.mesh.set_position(pos);

View File

@@ -42,7 +42,7 @@ fn main() -> Result<()> {
let file = File::open(FILE_PATH)?;
let mut buf = BufReader::new(file);
let mut mesh = load_mesh(&mut buf, "stl")?;
let (min, max) = mesh.minmax_point();
let (min, max) = mesh.bounds();
// Scale the model into printer-space (mm => px)
let real_scale = 1.0;

View File

@@ -191,8 +191,8 @@ impl Mesh {
/// Get the minimum and maximum of each component of every vertex in the
/// model. These points define the bounding box of the model.
pub fn minmax_point(&self) -> (Pos, Pos) {
minmax_vertices(self.vertices(), &self.transformation_matrix)
pub fn bounds(&self) -> (Pos, Pos) {
vertex_bounds(self.vertices(), &self.transformation_matrix)
}
}
@@ -350,7 +350,7 @@ impl Default for Mesh {
// todo: maybe only transform min and max at end
/// Get the minimum and maximum of each component of every vertex.
/// These points define the bounding box of the model.
fn minmax_vertices(vertices: &[Pos], transform: &Matrix4<f32>) -> (Pos, Pos) {
fn vertex_bounds(vertices: &[Pos], transform: &Matrix4<f32>) -> (Pos, Pos) {
vertices.iter().fold(
(
Pos::new(f32::MAX, f32::MAX, f32::MAX),
@@ -368,7 +368,7 @@ fn minmax_vertices(vertices: &[Pos], transform: &Matrix4<f32>) -> (Pos, Pos) {
/// Moves the model to have its origin at its centerpoint.
fn center_vertices(vertices: &mut [Pos]) {
let (min, max) = minmax_vertices(vertices, &Matrix4::identity());
let (min, max) = vertex_bounds(vertices, &Matrix4::identity());
let center = (min + max) / 2.0;
let center = Pos::new(center.x, center.y, min.z);

View File

@@ -17,7 +17,7 @@ pub struct Segments1D {
impl Segments1D {
/// Creates a new Segments structure from a given mesh and segment count.
pub fn from_mesh(mesh: &Mesh, layer_count: usize) -> Self {
let (min, max) = mesh.minmax_point();
let (min, max) = mesh.bounds();
// Caching transformed points makes slicing faster.
let transformed_points = mesh
@@ -32,7 +32,7 @@ impl Segments1D {
// Adds the index of each face into all of the segments it covers.
for face in 0..mesh.face_count() {
let (min_height, max_height) = minmax_triangle_height(mesh, &transformed_points, face);
let (min_height, max_height) = triangle_bounds(mesh, &transformed_points, face);
let (min_layer, max_layer) = (
((min_height - min.z) / layer_height) as usize,
((max_height - min.z) / layer_height).round() as usize,
@@ -74,7 +74,7 @@ impl Segments1D {
}
/// Gets the min and max heights of the vertices of a face.
fn minmax_triangle_height(mesh: &Mesh, points: &[Vector3<f32>], triangle: usize) -> (f32, f32) {
fn triangle_bounds(mesh: &Mesh, points: &[Vector3<f32>], triangle: usize) -> (f32, f32) {
let triangle = mesh.faces()[triangle];
let heights = (
points[triangle[0] as usize].z,