• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Razakhel / RaZ / 17879500877

20 Sep 2025 11:50AM UTC coverage: 74.251% (+0.003%) from 74.248%
17879500877

push

github

Razakhel
[Utils/Shape] Optimized the AABB's point containment check

- The check is now done in the box's local space, granting a speedup of around 30%
  - It's possible to go further by precomputing the centroid & half-extents, giving a speedup of around 64%, but is left for another time as other shapes might benefit from caching data too

- Added a tolerance to handle calculation errors

17 of 25 new or added lines in 3 files covered. (68.0%)

1 existing line in 1 file now uncovered.

8348 of 11243 relevant lines covered (74.25%)

1757.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.59
/src/RaZ/Physics/Collider.cpp
1
#include "RaZ/Physics/Collider.hpp"
2
#include "RaZ/Utils/Shape.hpp"
3

4
namespace Raz {
5

6
Collider::Collider(Shape&& shape) {
3✔
7
  setShape(std::move(shape));
3✔
8
}
3✔
9

10
void Collider::setShape(Shape&& shape) {
7✔
11
  m_shapeType = shape.getType();
7✔
12

13
  switch (m_shapeType) {
7✔
14
    case ShapeType::LINE:
1✔
15
      m_colliderShape = std::make_unique<Line>(static_cast<Line&&>(shape));
1✔
16
      break;
1✔
17

18
    case ShapeType::PLANE:
3✔
19
      m_colliderShape = std::make_unique<Plane>(static_cast<Plane&&>(shape));
3✔
20
      break;
3✔
21

22
    case ShapeType::SPHERE:
2✔
23
      m_colliderShape = std::make_unique<Sphere>(static_cast<Sphere&&>(shape));
2✔
24
      break;
2✔
25

26
    case ShapeType::TRIANGLE:
×
27
      m_colliderShape = std::make_unique<Triangle>(static_cast<Triangle&&>(shape));
×
28
      break;
×
29

30
    case ShapeType::QUAD:
×
31
      m_colliderShape = std::make_unique<Quad>(static_cast<Quad&&>(shape));
×
32
      break;
×
33

34
    case ShapeType::AABB:
1✔
35
      m_colliderShape = std::make_unique<AABB>(static_cast<AABB&&>(shape));
1✔
36
      break;
1✔
37

38
    case ShapeType::OBB:
×
39
      m_colliderShape = std::make_unique<OBB>(static_cast<OBB&&>(shape));
×
40
      break;
×
41

42
    default:
×
NEW
43
      throw std::invalid_argument("[Collider] Unhandled shape type to create a collider from");
×
44
  }
45
}
7✔
46

47
bool Collider::intersects(const Shape& shape) const {
62✔
48
  switch (m_shapeType) {
62✔
49
    case ShapeType::LINE:
×
50
      return shape.intersects(static_cast<const Line&>(*m_colliderShape));
×
51

52
    case ShapeType::PLANE:
60✔
53
      return shape.intersects(static_cast<const Plane&>(*m_colliderShape));
60✔
54

55
    case ShapeType::SPHERE:
2✔
56
      return shape.intersects(static_cast<const Sphere&>(*m_colliderShape));
2✔
57

58
    case ShapeType::TRIANGLE:
×
59
      return shape.intersects(static_cast<const Triangle&>(*m_colliderShape));
×
60

61
    case ShapeType::QUAD:
×
62
      return shape.intersects(static_cast<const Quad&>(*m_colliderShape));
×
63

64
    case ShapeType::AABB:
×
65
      return shape.intersects(static_cast<const AABB&>(*m_colliderShape));
×
66

67
    case ShapeType::OBB:
×
68
      return shape.intersects(static_cast<const OBB&>(*m_colliderShape));
×
69

70
    default:
×
71
      break;
×
72
  }
73

NEW
74
  throw std::invalid_argument("[Collider] Unhandled shape type to check a collision with");
×
75
}
76

77
bool Collider::intersects(const Ray& ray, RayHit* hit) const {
4✔
78
  switch (m_shapeType) {
4✔
79
    case ShapeType::LINE:
×
80
      //return ray.intersects(static_cast<const Line&>(*m_colliderShape), hit);
81
      break;
×
82

83
    case ShapeType::PLANE:
2✔
84
      return ray.intersects(static_cast<const Plane&>(*m_colliderShape), hit);
2✔
85

86
    case ShapeType::SPHERE:
2✔
87
      return ray.intersects(static_cast<const Sphere&>(*m_colliderShape), hit);
2✔
88

89
    case ShapeType::TRIANGLE:
×
90
      return ray.intersects(static_cast<const Triangle&>(*m_colliderShape), hit);
×
91

92
    case ShapeType::QUAD:
×
93
      //return ray.intersects(static_cast<const Quad&>(*m_colliderShape), hit);
94
      break;
×
95

96
    case ShapeType::AABB:
×
97
      return ray.intersects(static_cast<const AABB&>(*m_colliderShape), hit);
×
98

99
    case ShapeType::OBB:
×
100
      //return ray.intersects(static_cast<const OBB&>(*m_colliderShape), hit);
101
      break;
×
102

103
    default:
×
104
      break;
×
105
  }
106

NEW
107
  throw std::invalid_argument("[Collider] Unhandled shape type to check an intersection with");
×
108
}
109

110
} // namespace Raz
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc