Computes the intersection with the given line segment in the shape's coordinate system.
33 Coord minPoint =
size / -2;
34 Coord maxPoint =
size / 2;
35 intersection1 = intersection2 = normal1 = normal2 =
Coord::NIL;
36 const Coord& point1 = lineSegment.getPoint1();
37 const Coord& point2 = lineSegment.getPoint2();
41 intersection1 = point1;
43 intersection2 = point2;
44 if (isInside1 && isInside2)
47 Coord xMinNormal(-1, 0, 0);
48 Coord xMinIntersecion = Plane(minPoint, xMinNormal).computeIntersection(lineSegment);
49 if (!xMinIntersecion.isNil() &&
isInsideY(xMinIntersecion) &&
isInsideZ(xMinIntersecion)) {
50 if (point1.x < minPoint.x) {
51 intersection1 = xMinIntersecion;
55 intersection2 = xMinIntersecion;
60 Coord xMaxNormal(1, 0, 0);
61 Coord xMaxIntersection = Plane(maxPoint, xMaxNormal).computeIntersection(lineSegment);
62 if (!xMaxIntersection.isNil() &&
isInsideY(xMaxIntersection) &&
isInsideZ(xMaxIntersection)) {
63 if (point1.x > maxPoint.x) {
64 intersection1 = xMaxIntersection;
68 intersection2 = xMaxIntersection;
73 Coord yMinNormal(0, -1, 0);
74 Coord yMinIntersection = Plane(minPoint, yMinNormal).computeIntersection(lineSegment);
75 if (!yMinIntersection.isNil() &&
isInsideX(yMinIntersection) &&
isInsideZ(yMinIntersection)) {
76 if (point1.y < minPoint.y) {
77 intersection1 = yMinIntersection;
81 intersection2 = yMinIntersection;
86 Coord yMaxNormal(0, 1, 0);
87 Coord yMaxIntersection = Plane(maxPoint, yMaxNormal).computeIntersection(lineSegment);
88 if (!yMaxIntersection.isNil() &&
isInsideX(yMaxIntersection) &&
isInsideZ(yMaxIntersection)) {
89 if (point1.y > maxPoint.y) {
90 intersection1 = yMaxIntersection;
94 intersection2 = yMaxIntersection;
99 Coord zMinNormal(0, 0, -1);
100 Coord zMinIntersection = Plane(minPoint, zMinNormal).computeIntersection(lineSegment);
101 if (!zMinIntersection.isNil() &&
isInsideX(zMinIntersection) &&
isInsideY(zMinIntersection)) {
102 if (point1.z < minPoint.z) {
103 intersection1 = zMinIntersection;
104 normal1 = zMinNormal;
107 intersection2 = zMinIntersection;
108 normal2 = zMinNormal;
112 Coord zMaxNormal(0, 0, 1);
113 Coord zMaxIntersection = Plane(maxPoint, zMaxNormal).computeIntersection(lineSegment);
114 if (!zMaxIntersection.isNil() &&
isInsideX(zMaxIntersection) &&
isInsideY(zMaxIntersection)) {
115 if (point1.z > maxPoint.z) {
116 intersection1 = zMaxIntersection;
117 normal1 = zMaxNormal;
120 intersection2 = zMaxIntersection;
121 normal2 = zMaxNormal;
124 return !intersection1.isUnspecified() && !intersection2.isUnspecified();
bool isInsideY(const Coord &point) const
Definition: Cuboid.h:36
Coord size
Definition: Cuboid.h:32
bool isInsideX(const Coord &point) const
Definition: Cuboid.h:35
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:40
bool isInsideZ(const Coord &point) const
Definition: Cuboid.h:37