remesh-threejs 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3925,6 +3925,24 @@ class VertexRelocator {
3925
3925
  return vertex.type === VertexType.Manifold || vertex.type === VertexType.OpenBook;
3926
3926
  }
3927
3927
  }
3928
+ function safeMin(arr) {
3929
+ if (arr.length === 0) return 0;
3930
+ let min = arr[0];
3931
+ for (let i = 1; i < arr.length; i++) {
3932
+ const val = arr[i];
3933
+ if (val < min) min = val;
3934
+ }
3935
+ return min;
3936
+ }
3937
+ function safeMax(arr) {
3938
+ if (arr.length === 0) return 0;
3939
+ let max = arr[0];
3940
+ for (let i = 1; i < arr.length; i++) {
3941
+ const val = arr[i];
3942
+ if (val > max) max = val;
3943
+ }
3944
+ return max;
3945
+ }
3928
3946
  function computeMeshQuality(mesh, poorQualityThreshold = 0.3) {
3929
3947
  const faces = mesh.getFaces();
3930
3948
  const edges = mesh.getEdges();
@@ -3941,17 +3959,17 @@ function computeMeshQuality(mesh, poorQualityThreshold = 0.3) {
3941
3959
  }
3942
3960
  }
3943
3961
  const edgeLengths = edges.map((e) => e.length);
3944
- const minQuality = qualities.length > 0 ? Math.min(...qualities) : 0;
3945
- const maxQuality = qualities.length > 0 ? Math.max(...qualities) : 0;
3962
+ const minQuality = safeMin(qualities);
3963
+ const maxQuality = safeMax(qualities);
3946
3964
  const averageQuality = qualities.length > 0 ? qualities.reduce((a, b) => a + b, 0) / qualities.length : 0;
3947
3965
  const variance = qualities.length > 0 ? qualities.reduce((sum, q) => sum + Math.pow(q - averageQuality, 2), 0) / qualities.length : 0;
3948
3966
  const stdDevQuality = Math.sqrt(variance);
3949
3967
  const poorQualityCount = qualities.filter((q) => q < poorQualityThreshold).length;
3950
- const minEdgeLength = edgeLengths.length > 0 ? Math.min(...edgeLengths) : 0;
3951
- const maxEdgeLength = edgeLengths.length > 0 ? Math.max(...edgeLengths) : 0;
3968
+ const minEdgeLength = safeMin(edgeLengths);
3969
+ const maxEdgeLength = safeMax(edgeLengths);
3952
3970
  const averageEdgeLength = edgeLengths.length > 0 ? edgeLengths.reduce((a, b) => a + b, 0) / edgeLengths.length : 0;
3953
- const minArea = areas.length > 0 ? Math.min(...areas) : 0;
3954
- const maxArea = areas.length > 0 ? Math.max(...areas) : 0;
3971
+ const minArea = safeMin(areas);
3972
+ const maxArea = safeMax(areas);
3955
3973
  const totalArea = areas.reduce((a, b) => a + b, 0);
3956
3974
  return {
3957
3975
  minQuality,
@@ -4013,8 +4031,8 @@ function computeTriangleAspectRatio(face) {
4013
4031
  return null;
4014
4032
  }
4015
4033
  const lengths = halfedges.map((he) => he.edge.length);
4016
- const minLen = Math.min(...lengths);
4017
- const maxLen = Math.max(...lengths);
4034
+ const minLen = safeMin(lengths);
4035
+ const maxLen = safeMax(lengths);
4018
4036
  if (minLen < 1e-10) {
4019
4037
  return Infinity;
4020
4038
  }