test_constraints_cylindersurface.cc 4.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cmath>
#include <string>
#include <stdexcept>

#include <frackit/geometry/disk.hh>
#include <frackit/geometry/cylindersurface.hh>
#include <frackit/entitynetwork/constraints.hh>

//! test the constraints for entity networks of disks
int main()
{
    using ctype = double;

    using CylinderSurface = Frackit::CylinderSurface<ctype>;
    using Disk = Frackit::Disk<ctype>;
    using Point = typename Disk::Point;
    using Direction = typename Disk::Direction;
    using Vector = typename Direction::Vector;
19
    using Violation = Frackit::ConstraintsEvaluation::Violation;
20
21
22
23
24
25
26

    // Basis Vectors
    const Vector e1(1.0, 0.0, 0.0);
    const Vector e2(0.0, 1.0, 0.0);
    const Vector e3(0.0, 0.0, 1.0);

    // Define constraints
27
    auto constraints = Frackit::makeDefaultConstraints<ctype>();
28
29
30
31
32
33
34
35
36
37
38
    constraints.setMinDistance(0.1);
    constraints.setMinIntersectingAngle(M_PI/4.0);
    constraints.setMinIntersectionMagnitude(0.05);
    constraints.setMinIntersectionDistance(0.05);

    // The cylinder surface to test against
    CylinderSurface cylSurface(0.5, 1.0);

    // violates distance constraint
    Disk disk1(Point(0.0, 0.0, 0.5), e1, e2, 0.4+1e-5, 0.25);
    if (constraints.evaluate(cylSurface, disk1))
39
40
        throw std::runtime_error("False positive detected");
    if (constraints.evaluate(cylSurface, disk1).violation() != Violation::distance)
41
        throw std::runtime_error("Did not detect distance violation");
42
43
44
45
46
    std::cout << "Test 1 passed" << std::endl;

    // just doesn't violate distance constraint
    Disk disk2(Point(0.0, 0.0, 0.5), e1, e2, 0.4-1e-5, 0.25);
    if (!constraints.evaluate(cylSurface, disk2))
47
        throw std::runtime_error("False positive distance violation");
48
49
    if (constraints.evaluate(cylSurface, disk2).violation() != Violation::none)
        throw std::runtime_error("False positive distance violation");
50
51
52
53
54
    std::cout << "Test 2 passed" << std::endl;

    // violates the intersection magnitude constraint
    Disk disk3(Point(0.4, 0.0, 0.5), e1, e2, 0.11, 0.05);
    if (constraints.evaluate(cylSurface, disk3))
55
        throw std::runtime_error("Did not detect intersection magnitude violation");
56
57
    if (constraints.evaluate(cylSurface, disk3).violation() != Violation::intersectionMagnitude)
        throw std::runtime_error("Did not detect intersection magnitude violation");
58
59
60
61
62
    std::cout << "Test 3 passed" << std::endl;

    // does not violate the intersection magnitude constraint
    Disk disk4(Point(0.4, 0.0, 0.5), e1, e2, 0.5, 0.5);
    if (!constraints.evaluate(cylSurface, disk4))
63
        throw std::runtime_error("False positive intersection magnitude violation");
64
65
    if (constraints.evaluate(cylSurface, disk4).violation() != Violation::none)
        throw std::runtime_error("False positive intersection magnitude violation");
66
67
68
69
70
    std::cout << "Test 4 passed" << std::endl;

    // violates the distance to boundary constraint
    Disk disk5(Point(0.4, 0.0, 0.95 + 1e-6), e1, e2, 0.5, 0.5);
    if (constraints.evaluate(cylSurface, disk5))
71
        throw std::runtime_error("Did not detect distance to boundary violation");
72
73
    if (constraints.evaluate(cylSurface, disk5).violation() != Violation::intersectionDistance)
        throw std::runtime_error("Did not detect distance to boundary violation");
74
75
76
77
78
    std::cout << "Test 5 passed" << std::endl;

    // does not violate the distance to boundary constraint
    Disk disk6(Point(0.4, 0.0, 0.95 - 1e-6), e1, e2, 0.5, 0.5);
    if (!constraints.evaluate(cylSurface, disk6))
79
        throw std::runtime_error("False positive intersection magnitude violation");
80
81
    if (constraints.evaluate(cylSurface, disk6).violation() != Violation::none)
        throw std::runtime_error("False positive intersection magnitude violation");
82
83
84
85
86
87
    std::cout << "Test 6 passed" << std::endl;

    // violates the intersection angle constraint
    const Vector e12(1.0, 0.0, 1.0 + 1e-3);
    Disk disk7(Point(0.4, 0.0, 0.5), e12, e2, 0.5, 0.5);
    if (constraints.evaluate(cylSurface, disk7))
88
        throw std::runtime_error("Did not detect intersection angle violation");
89
90
    if (constraints.evaluate(cylSurface, disk7).violation() != Violation::intersectionAngle)
        throw std::runtime_error("Did not detect intersection angle violation");
91
92
93
94
95
    std::cout << "Test 7 passed" << std::endl;

    // does not violate the distance to boundary constraint
    Disk disk8(Point(0.4, 0.0, 0.95 - 1e-6), e1, e2, 0.5, 0.5);
    if (!constraints.evaluate(cylSurface, disk6))
96
        throw std::runtime_error("False positive intersection magnitude violation");
97
98
    if (constraints.evaluate(cylSurface, disk6).violation() != Violation::none)
        throw std::runtime_error("False positive intersection magnitude violation");
99
100
101
102
103
104
105
    std::cout << "Test 6 passed" << std::endl;

    // TODO: Test elliptical intersection

    std::cout << "All tests passed" << std::endl;
    return 0;
}