Skip to content

Commit 62e431e

Browse files
authored
Merge pull request #14 from Andlon/missing_apis
Missing apis
2 parents d7622a8 + e954eed commit 62e431e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/element/triangle.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,31 @@ pub struct Tri3d3Element<T>
316316
where
317317
T: Scalar,
318318
{
319-
triangle: Triangle3d<T>,
319+
vertices: [Point3<T>; 3],
320+
}
321+
322+
impl<T: Scalar> Tri3d3Element<T> {
323+
pub fn from_vertices(vertices: [Point3<T>; 3]) -> Self {
324+
Self { vertices }
325+
}
326+
327+
pub fn vertices(&self) -> &[Point3<T>; 3] {
328+
&self.vertices
329+
}
330+
}
331+
332+
impl<'a, T: Scalar> From<&'a Tri3d3Element<T>> for Triangle3d<T> {
333+
fn from(element: &'a Tri3d3Element<T>) -> Self {
334+
Triangle(element.vertices.clone())
335+
}
320336
}
321337

322338
impl<T> From<Triangle3d<T>> for Tri3d3Element<T>
323339
where
324340
T: Scalar,
325341
{
326342
fn from(triangle: Triangle3d<T>) -> Self {
327-
Self { triangle }
343+
Self::from_vertices(triangle.0)
328344
}
329345
}
330346

@@ -367,23 +383,22 @@ where
367383

368384
#[allow(non_snake_case)]
369385
fn reference_jacobian(&self, xi: &Point2<T>) -> Matrix3x2<T> {
370-
let X: Matrix3<T> = Matrix3::from_fn(|i, j| self.triangle.0[j][i]);
386+
let X: Matrix3<T> = Matrix3::from_fn(|i, j| self.vertices[j][i]);
371387
let G = self.gradients(xi);
372388
X * G.transpose()
373389
}
374390

375391
#[allow(non_snake_case)]
376392
fn map_reference_coords(&self, xi: &Point2<T>) -> Point3<T> {
377393
// TODO: Store this X matrix directly in Self...?
378-
let X: Matrix3<T> = Matrix3::from_fn(|i, j| self.triangle.0[j][i]);
394+
let X: Matrix3<T> = Matrix3::from_fn(|i, j| self.vertices[j][i]);
379395
let N = self.evaluate_basis(xi);
380396
OPoint::from(&X * &N.transpose())
381397
}
382398

383399
// TODO: Write tests for diameter
384400
fn diameter(&self) -> T {
385-
self.triangle
386-
.0
401+
self.vertices
387402
.iter()
388403
.tuple_combinations()
389404
.map(|(x, y)| distance(x, y))
@@ -396,7 +411,7 @@ where
396411
T: RealField,
397412
{
398413
fn normal(&self, _xi: &Point2<T>) -> Vector3<T> {
399-
self.triangle.normal()
414+
Triangle3d::from(self).normal()
400415
}
401416
}
402417

src/mesh.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ where
243243
self.transform_vertices(|p| *p += translation);
244244
}
245245

246+
/// Consumes the mesh and returns it translated by the given translation vector.
247+
pub fn translated(mut self, translation: &OVector<T, D>) -> Self {
248+
self.translate(&translation);
249+
self
250+
}
251+
246252
/// Transform all vertices of the mesh by the given transformation function.
247253
pub fn transform_vertices<F>(&mut self, mut transformation: F)
248254
where

0 commit comments

Comments
 (0)