Skip to content
Snippets Groups Projects
Commit f5670a07 authored by Daniel Schramm's avatar Daniel Schramm
Browse files

Tests for DistanceToTrianglesKdVisitor implemented

parent e4a234b4
No related branches found
No related tags found
No related merge requests found
package cz.fidentis.analyst.visitors.kdtree;
import cz.fidentis.analyst.kdtree.KdTree;
import cz.fidentis.analyst.kdtree.KdTreeVisitor;
import cz.fidentis.analyst.mesh.core.CornerTableRow;
import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshFacetImpl;
import cz.fidentis.analyst.mesh.core.MeshPoint;
import cz.fidentis.analyst.mesh.core.MeshPointImpl;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.vecmath.Vector3d;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class DistanceToTrianglesKdVisitorTest {
protected MeshFacet getTrivialFacet(double offset, double size) {
MeshFacet facet = new MeshFacetImpl();
facet.addVertex(new MeshPointImpl(new Vector3d(0, 0, offset), new Vector3d(0, 0, 1), new Vector3d()));
facet.addVertex(new MeshPointImpl(new Vector3d(size, 0, offset), new Vector3d(0, 0, 1), new Vector3d()));
facet.addVertex(new MeshPointImpl(new Vector3d(0, size, offset), new Vector3d(0, 0, 1), new Vector3d()));
facet.getCornerTable().addRow(new CornerTableRow(0, -1));
facet.getCornerTable().addRow(new CornerTableRow(1, -1));
facet.getCornerTable().addRow(new CornerTableRow(2, -1));
return facet;
}
protected void distTest(double expectedDist, DistanceToTrianglesKdVisitor vis) {
KdTree tree = new KdTree(getTrivialFacet(1.5, 1));
tree.accept(vis);
assertEquals(expectedDist, vis.getDistance());
}
protected void concurrentDistTest(double expectedDist, DistanceToTrianglesKdVisitor vis) throws InterruptedException, ExecutionException {
final int threads = Runtime.getRuntime().availableProcessors();
final ExecutorService executor = Executors.newFixedThreadPool(threads);
final List<Future<KdTreeVisitor>> results = new LinkedList<>();
final KdTree tree = new KdTree(getTrivialFacet(1.5, 1));
tree.accept(vis);
final Future<KdTreeVisitor> result = executor.submit(vis);
results.add(result);
results.get(0).get();
assertEquals(expectedDist, vis.getDistance());
}
@Test
public void absoluteDistTest() {
MeshPoint point = new MeshPointImpl(new Vector3d(0,0,0), new Vector3d(0,0,-1), new Vector3d());
DistanceToTrianglesKdVisitor vis = new DistanceToTrianglesKdVisitor(point, false, false); // sequentially
distTest(1.5, vis);
}
@Test
public void relativeDistTest() {
MeshPoint point = new MeshPointImpl(new Vector3d(0,0,0), new Vector3d(0,0,-1), new Vector3d());
DistanceToTrianglesKdVisitor vis = new DistanceToTrianglesKdVisitor(point, true, false); // sequentially
distTest(-1.5, vis);
}
@Test
public void exactMatchTest() {
MeshPoint point = new MeshPointImpl(new Vector3d(0, 0, 1.5), new Vector3d(0, 0, 1), new Vector3d());
DistanceToTrianglesKdVisitor vis = new DistanceToTrianglesKdVisitor(point, true, false); // relative dist, sequentially
distTest(0, vis);
vis = new DistanceToTrianglesKdVisitor(point, false, false); // abosolute dist, sequentially
distTest(0, vis);
}
@Test
public void concurrencyTest() throws InterruptedException, ExecutionException {
MeshPoint point = new MeshPointImpl(new Vector3d(0,0,0), new Vector3d(0,0,-1), new Vector3d());
DistanceToTrianglesKdVisitor vis = new DistanceToTrianglesKdVisitor(point, false, true); // absolute dist, concurrently
concurrentDistTest(1.5, vis);
vis = new DistanceToTrianglesKdVisitor(point, true, true); // relative dist, concurrently
concurrentDistTest(-1.5, vis);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment