Skip to content

Commit

Permalink
fix wavefront tests + new test for different pos + add them in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Sep 12, 2024
1 parent 0928147 commit 6e1769c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/parry-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: parry CI build

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Check serialization
run: cargo check --features bytemuck-serialize,serde-serialize,rkyv-serialize;
- name: Run tests
run: cargo test
run: cargo test --features wavefront
build-wasm:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -74,6 +74,6 @@ jobs:
- name: install stable Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
toolchain: stable
- name: cargo doc
run: cargo doc --workspace --features bytemuck-serialize,serde-serialize,rkyv-serialize,parallel --no-deps --document-private-items
48 changes: 37 additions & 11 deletions src/transformation/mesh_intersection/mesh_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use crate::query::{visitors::BoundingVolumeIntersectionsSimultaneousVisitor, Poi
use crate::shape::{TriMesh, Triangle};
use crate::utils;
use na::{Point3, Vector3};
#[cfg(feature = "wavefront")]
use obj::{Group, IndexTuple, ObjData, Object, SimplePolygon};
use rstar::RTree;
use spade::{ConstrainedDelaunayTriangulation, InsertionError, Triangulation as _};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -668,9 +666,10 @@ fn merge_triangle_sets(
#[cfg(test)]
mod tests {
use super::*;
use crate::shape::TriMeshFlags;
use crate::transformation::wavefront::*;
use crate::bounding_volume::{bounding_sphere, BoundingSphere};
use crate::shape::{Ball, Cuboid, TriMeshFlags};
use obj::Obj;
use obj::ObjData;

#[test]
fn test_same_mesh_intersection() {
Expand All @@ -684,7 +683,7 @@ mod tests {
let mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand All @@ -708,6 +707,33 @@ mod tests {
mesh.to_obj_file(&PathBuf::from("same_test.obj"));
}

#[test]
fn test_non_origin_pos1_pos2_intersection() {
let ball = Ball::new(2f32 as Real).to_trimesh(10, 10);
let cuboid = Cuboid::new(Vector3::new(2.0, 1.0, 1.0)).to_trimesh();
let mut sphere_mesh = TriMesh::new(ball.0, ball.1);
sphere_mesh.set_flags(TriMeshFlags::all()).unwrap();
let mut cuboid_mesh = TriMesh::new(cuboid.0, cuboid.1);
cuboid_mesh.set_flags(TriMeshFlags::all()).unwrap();

let res = intersect_meshes(
&Isometry::translation(1.0, 0.0, 0.0),
&cuboid_mesh,
false,
&Isometry::translation(2.0, 0.0, 0.0),
&sphere_mesh, //.clone().scaled(&Vector3::new(1.001, 1.001, 1.001)),
false,
)
.unwrap()
.unwrap();

let _ = res.to_obj_file(&PathBuf::from("test_non_origin_pos1_pos2_intersection.obj"));

let bounding_sphere = res.local_bounding_sphere();
assert!(bounding_sphere.center == Point3::new(1.5, 0.0, 0.0));
assert_relative_eq!(2.0615528, bounding_sphere.radius, epsilon = 1.0e-5);
}

#[test]
fn test_offset_cylinder_intersection() {
let Obj {
Expand All @@ -720,7 +746,7 @@ mod tests {
let offset_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand All @@ -740,7 +766,7 @@ mod tests {
let center_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand Down Expand Up @@ -776,7 +802,7 @@ mod tests {
let stair_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand All @@ -796,7 +822,7 @@ mod tests {
let bar_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand Down Expand Up @@ -832,7 +858,7 @@ mod tests {
let bunny_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand All @@ -852,7 +878,7 @@ mod tests {
let cylinder_mesh = TriMesh::with_flags(
position
.iter()
.map(|v| Point3::new(v[0] as f64, v[1] as f64, v[2] as f64))
.map(|v| Point3::new(v[0] as Real, v[1] as Real, v[2] as Real))
.collect::<Vec<_>>(),
objects[0].groups[0]
.polys
Expand Down

0 comments on commit 6e1769c

Please sign in to comment.