24 template <
typename Real>
45 Result
operator()(std::array<Real, 2>
const& interval0,
46 std::array<Real, 2>
const& interval1);
49 Result
operator()(Real maxTime, std::array<Real, 2>
const& interval0,
50 Real speed0, std::array<Real, 2>
const& interval1, Real speed1);
53 template <
typename Real>
85 Result
operator()(std::array<Real, 2>
const& interval0,
86 std::array<Real, 2>
const& interval1);
89 Result
operator()(Real maxTime, std::array<Real, 2>
const& interval0,
90 Real speed0, std::array<Real, 2>
const& interval1, Real speed1);
94 template <
typename Real>
98 template <
typename Real>
103 template <
typename Real>
106 std::array<Real, 2>
const& interval0,
107 std::array<Real, 2>
const& interval1)
111 interval0[0] <= interval1[1] && interval0[1] >= interval1[0];
115 template <
typename Real>
118 Real maxTime, std::array<Real, 2>
const& interval0, Real speed0,
119 std::array<Real, 2>
const& interval1, Real speed1)
123 if (interval0[1] < interval1[0])
126 Real diffSpeed = speed0 - speed1;
127 if (diffSpeed > (Real)0)
131 Real diffPos = interval1[0] - interval0[1];
132 Real invDiffSpeed = ((Real)1) / diffSpeed;
133 result.intersect = (diffPos <= maxTime*diffSpeed);
134 result.firstTime = diffPos*invDiffSpeed;
135 result.lastTime = (interval1[1] - interval0[0])*invDiffSpeed;
139 else if (interval0[0] > interval1[1])
142 Real diffSpeed = speed1 - speed0;
143 if (diffSpeed > (Real)0)
147 Real diffPos = interval0[0] - interval1[1];
148 Real invDiffSpeed = ((Real)1) / diffSpeed;
149 result.intersect = (diffPos <= maxTime*diffSpeed);
150 result.firstTime = diffPos*invDiffSpeed;
151 result.lastTime = (interval0[1] - interval1[0])*invDiffSpeed;
158 result.intersect =
true;
159 result.firstTime = (Real)0;
162 result.lastTime = (interval0[1] - interval1[0])/(speed1 - speed0);
164 else if (speed1 < speed0)
166 result.lastTime = (interval1[1] - interval0[0])/(speed0 - speed1);
170 result.lastTime = std::numeric_limits<Real>::max();
175 result.intersect =
false;
176 result.firstTime = std::numeric_limits<Real>::max();
177 result.lastTime = -std::numeric_limits<Real>::max();
183 template <
typename Real>
186 std::array<Real, 2>
const& interval0,
187 std::array<Real, 2>
const& interval1)
190 result.firstTime = std::numeric_limits<Real>::max();
191 result.lastTime = -std::numeric_limits<Real>::max();
193 if (interval0[1] < interval1[0] || interval0[0] > interval1[1])
195 result.numIntersections = 0;
196 result.overlap[0] = std::numeric_limits<Real>::max();
197 result.overlap[1] = -std::numeric_limits<Real>::max();
199 else if (interval0[1] > interval1[0])
201 if (interval0[0] < interval1[1])
203 result.numIntersections = 2;
205 (interval0[0] < interval1[0] ? interval1[0] : interval0[0]);
207 (interval0[1] > interval1[1] ? interval1[1] : interval0[1]);
208 if (result.overlap[0] == result.overlap[1])
210 result.numIntersections = 1;
215 result.numIntersections = 1;
216 result.overlap[0] = interval0[0];
217 result.overlap[1] = result.overlap[0];
222 result.numIntersections = 1;
223 result.overlap[0] = interval0[1];
224 result.overlap[1] = result.overlap[0];
227 result.intersect = (result.numIntersections > 0);
231 template <
typename Real>
234 Real maxTime, std::array<Real, 2>
const& interval0, Real speed0,
235 std::array<Real, 2>
const& interval1, Real speed1)
239 if (interval0[1] < interval1[0])
242 Real diffSpeed = speed0 - speed1;
243 if (diffSpeed > (Real)0)
247 Real diffPos = interval1[0] - interval0[1];
248 Real invDiffSpeed = ((Real)1) / diffSpeed;
249 result.intersect = (diffPos <= maxTime*diffSpeed);
250 result.numIntersections = 1;
251 result.firstTime = diffPos*invDiffSpeed;
252 result.lastTime = (interval1[1] - interval0[0])*invDiffSpeed;
253 result.overlap[0] = interval0[0] + result.firstTime*speed0;
254 result.overlap[1] = result.overlap[0];
258 else if (interval0[0] > interval1[1])
261 Real diffSpeed = speed1 - speed0;
262 if (diffSpeed > (Real)0)
266 Real diffPos = interval0[0] - interval1[1];
267 Real invDiffSpeed = ((Real)1) / diffSpeed;
268 result.intersect = (diffPos <= maxTime*diffSpeed);
269 result.numIntersections = 1;
270 result.firstTime = diffPos*invDiffSpeed;
271 result.lastTime = (interval0[1] - interval1[0])*invDiffSpeed;
272 result.overlap[0] = interval1[1] + result.firstTime*speed1;
273 result.overlap[1] = result.overlap[0];
280 result.intersect =
true;
281 result.firstTime = (Real)0;
284 result.lastTime = (interval0[1] - interval1[0]) / (speed1 - speed0);
286 else if (speed1 < speed0)
288 result.lastTime = (interval1[1] - interval0[0]) / (speed0 - speed1);
292 result.lastTime = std::numeric_limits<Real>::max();
295 if (interval0[1] > interval1[0])
297 if (interval0[0] < interval1[1])
299 result.numIntersections = 2;
300 result.overlap[0] = (interval0[0] < interval1[0] ?
301 interval1[0] : interval0[0]);
302 result.overlap[1] = (interval0[1] > interval1[1] ?
303 interval1[1] : interval0[1]);
307 result.numIntersections = 1;
308 result.overlap[0] = interval0[0];
309 result.overlap[1] = result.overlap[0];
314 result.numIntersections = 1;
315 result.overlap[0] = interval0[1];
316 result.overlap[1] = result.overlap[0];
321 result.intersect =
false;
322 result.numIntersections = 0;
323 result.overlap[0] = std::numeric_limits<Real>::max();
324 result.overlap[1] = -std::numeric_limits<Real>::max();
325 result.firstTime = std::numeric_limits<Real>::max();
326 result.lastTime = -std::numeric_limits<Real>::max();
std::array< Real, 2 > overlap
Result operator()(Type0 const &primitive0, Type1 const &primitive1)