22 template <
typename Real>
40 template <
typename Real>
49 int const numVertices =
static_cast<int>(polygon.size());
50 std::vector<Real>
distance(numVertices);
51 int positive = 0, negative = 0, positiveIndex = -1;
52 for (
int i = 0; i < numVertices; ++i)
54 distance[i] =
Dot(halfspace.normal, polygon[i]) - halfspace.constant;
55 if (distance[i] > (Real)0)
58 if (positiveIndex == -1)
63 else if (distance[i] < (Real)0)
72 result.intersect =
false;
80 result.intersect =
true;
89 if (positiveIndex > 0)
94 t = distance[curr] / (distance[curr] - distance[prev]);
95 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
96 result.polygon.push_back(vertex);
99 while (curr < numVertices && distance[curr] >(Real)0)
101 result.polygon.push_back(polygon[curr++]);
105 if (curr < numVertices)
112 prev = numVertices - 1;
114 t = distance[curr] / (distance[curr] - distance[prev]);
115 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
116 result.polygon.push_back(vertex);
122 while (curr < numVertices && distance[curr] >(Real)0)
124 result.polygon.push_back(polygon[curr++]);
129 t = distance[curr] / (distance[curr] - distance[prev]);
130 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
131 result.polygon.push_back(vertex);
134 while (curr < numVertices && distance[curr] <= (Real)0)
140 if (curr < numVertices)
143 t = distance[curr] / (distance[curr] - distance[prev]);
144 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
145 result.polygon.push_back(vertex);
148 while (curr < numVertices && distance[curr] >(Real)0)
150 result.polygon.push_back(polygon[curr++]);
156 prev = numVertices - 1;
157 t = distance[curr] / (distance[curr] - distance[prev]);
158 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
159 result.polygon.push_back(vertex);
163 result.intersect =
true;
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLsizei GLsizei GLfloat distance
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
std::vector< Vector2< Real > > polygon