Prepare to re-use fj_math::Scalar

This commit is contained in:
Hanno Braun 2025-03-21 22:12:52 +01:00
parent 837a8df28c
commit 4a2277d3e7
4 changed files with 16 additions and 12 deletions

View File

@ -24,7 +24,9 @@ pub fn export(tri_mesh: &TriMesh) -> anyhow::Result<()> {
vertices: threemf::model::Vertices {
vertex: points
.into_iter()
.map(|point| point.coords.components.map(|coord| coord.value()))
.map(|point| {
point.coords.components.map(|coord| coord.into_f64())
})
.map(|[x, y, z]| threemf::model::Vertex { x, y, z })
.collect(),
},

View File

@ -23,7 +23,8 @@ pub fn triangulate(face: &Face) -> TriMesh {
let points = triangle.map(|point| point.point_surface);
let triangle = Triangle { points };
let [x, y] = triangle.center().coords.components.map(|s| s.value());
let [x, y] =
triangle.center().coords.components.map(|s| s.into_f64());
polygon.contains(&Coord { x, y })
})
.map(|triangle| {
@ -101,7 +102,8 @@ fn polygon(points: &[TriangulationPoint]) -> Polygon {
continue;
}
let [x, y] = point.point_surface.coords.components.map(|s| s.value());
let [x, y] =
point.point_surface.coords.components.map(|s| s.into_f64());
current_line_string.push(Coord { x, y });
visited_points.insert(point);
}
@ -140,7 +142,7 @@ impl spade::HasPosition for TriangulationPoint {
type Scalar = f64;
fn position(&self) -> spade::Point2<Self::Scalar> {
let [x, y] = self.point_surface.coords.components.map(|s| s.value());
let [x, y] = self.point_surface.coords.components.map(|s| s.into_f64());
spade::Point2 { x, y }
}
}

View File

@ -19,12 +19,12 @@ impl Scalar {
Self { value }
}
pub fn value(self) -> f64 {
pub fn into_f64(self) -> f64 {
self.value
}
pub fn sqrt(self) -> Self {
let value = self.value().sqrt();
let value = self.into_f64().sqrt();
Self::from_f64(value)
}
}
@ -63,7 +63,7 @@ where
type Output = Self;
fn add(self, other: S) -> Self::Output {
let value = self.value() + other.into().value();
let value = self.into_f64() + other.into().into_f64();
Self::from_f64(value)
}
}
@ -75,7 +75,7 @@ where
type Output = Self;
fn div(self, other: S) -> Self::Output {
let value = self.value() / other.into().value();
let value = self.into_f64() / other.into().into_f64();
Self::from_f64(value)
}
}
@ -87,7 +87,7 @@ where
type Output = Self;
fn mul(self, other: S) -> Self::Output {
let value = self.value() * other.into().value();
let value = self.into_f64() * other.into().into_f64();
Self::from_f64(value)
}
}
@ -96,7 +96,7 @@ impl ops::Neg for Scalar {
type Output = Self;
fn neg(self) -> Self::Output {
let value = -self.value();
let value = -self.into_f64();
Self::from_f64(value)
}
}
@ -108,7 +108,7 @@ where
type Output = Self;
fn sub(self, other: S) -> Self::Output {
let value = self.value() - other.into().value();
let value = self.into_f64() - other.into().into_f64();
Self::from_f64(value)
}
}

View File

@ -19,7 +19,7 @@ impl Geometry {
for triangle in tri_mesh.all_triangles() {
let triangle = triangle.points.each_ref().map(|point| {
Vec3::from(
point.coords.components.map(|coord| coord.value() as f32),
point.coords.components.map(|coord| coord.into_f64() as f32),
)
});
let normal = {