39 #ifndef FCL_CCD_INTERVAL_INL_H 40 #define FCL_CCD_INTERVAL_INL_H 42 #include "fcl/math/motion/taylor_model/interval.h" 49 struct Interval<double>;
53 Interval<double> bound(
const Interval<double>& i,
double v);
57 Interval<double> bound(
const Interval<double>& i,
const Interval<double>& other);
61 Interval<S>::Interval()
68 Interval<S>::Interval(S v)
77 i_[0] = left; i_[1] = right;
102 template <
typename S>
109 template <
typename S>
112 if(i_[0] != other.i_[0])
return false;
113 if(i_[1] != other.i_[1])
return false;
118 template <
typename S>
121 return Interval(i_[0] + other.i_[0], i_[1] + other.i_[1]);
125 template <
typename S>
128 return Interval(i_[0] - other.i_[1], i_[1] - other.i_[0]);
132 template <
typename S>
135 i_[0] += other.i_[0];
136 i_[1] += other.i_[1];
141 template <
typename S>
144 i_[0] -= other.i_[1];
145 i_[1] -= other.i_[0];
150 template <
typename S>
155 if(i_[0] >= 0)
return Interval<S>(i_[0] * other.i_[0], i_[1] * other.i_[1]);
156 if(i_[1] <= 0)
return Interval<S>(i_[0] * other.i_[1], i_[1] * other.i_[0]);
157 return Interval<S>(i_[0] * other.i_[1], i_[1] * other.i_[1]);
161 if(i_[0] >= 0)
return Interval<S>(i_[1] * other.i_[0], i_[0] * other.i_[1]);
162 if(i_[1] <= 0)
return Interval<S>(i_[1] * other.i_[1], i_[0] * other.i_[0]);
163 return Interval<S>(i_[1] * other.i_[0], i_[0] * other.i_[0]);
166 if(i_[0] >= 0)
return Interval<S>(i_[1] * other.i_[0], i_[1] * other.i_[1]);
167 if(i_[1] <= 0)
return Interval<S>(i_[0] * other.i_[1], i_[0] * other.i_[0]);
169 S v00 = i_[0] * other.i_[0];
170 S v11 = i_[1] * other.i_[1];
173 S v01 = i_[0] * other.i_[1];
174 S v10 = i_[1] * other.i_[0];
179 S v01 = i_[0] * other.i_[1];
180 S v10 = i_[1] * other.i_[0];
186 template <
typename S>
193 i_[0] *= other.i_[0];
194 i_[1] *= other.i_[1];
198 i_[0] *= other.i_[1];
199 i_[1] *= other.i_[0];
203 i_[0] *= other.i_[1];
204 i_[1] *= other.i_[1];
214 i_[0] = i_[1] * other.i_[0];
215 i_[1] = tmp * other.i_[1];
220 i_[0] = i_[1] * other.i_[1];
221 i_[1] = tmp * other.i_[0];
226 i_[0] = i_[1] * other.i_[0];
227 i_[1] = tmp * other.i_[0];
234 i_[0] = i_[1] * other.i_[0];
235 i_[1] *= other.i_[1];
241 i_[1] = i_[0] * other.i_[0];
242 i_[0] *= other.i_[1];
246 S v00 = i_[0] * other.i_[0];
247 S v11 = i_[1] * other.i_[1];
250 S v01 = i_[0] * other.i_[1];
251 S v10 = i_[1] * other.i_[0];
265 S v01 = i_[0] * other.i_[1];
266 S v10 = i_[1] * other.i_[0];
282 template <
typename S>
285 if(d >= 0)
return Interval(i_[0] * d, i_[1] * d);
286 return Interval(i_[1] * d, i_[0] * d);
290 template <
typename S>
309 template <
typename S>
312 return *
this *
Interval(1.0 / other.i_[1], 1.0 / other.i_[0]);
316 template <
typename S>
319 *
this *=
Interval(1.0 / other.i_[1], 1.0 / other.i_[0]);
324 template <
typename S>
327 if(i_[1] < other.i_[0])
return false;
328 if(i_[0] > other.i_[1])
return false;
333 template <
typename S>
336 if(i_[1] < other.i_[0])
return false;
337 if(i_[0] > other.i_[1])
return false;
338 if(i_[1] > other.i_[1]) i_[1] = other.i_[1];
339 if(i_[0] < other.i_[0]) i_[0] = other.i_[0];
344 template <
typename S>
351 template <
typename S>
354 if(i_[0] >= 0)
return i_[0];
355 if(i_[1] >= 0)
return 0;
360 template <
typename S>
363 if(i_[0] + i_[1] >= 0)
return i_[1];
368 template <
typename S>
371 if(v < i_[0])
return false;
372 if(v > i_[1])
return false;
377 template <
typename S>
380 if(v < i_[0]) i_[0] = v;
381 if(v > i_[1]) i_[1] = v;
386 template <
typename S>
389 if(other.i_[0] < i_[0]) i_[0] = other.i_[0];
390 if(other.i_[1] > i_[1]) i_[1] = other.i_[1];
395 template <
typename S>
398 std::cout <<
"[" << i_[0] <<
", " << i_[1] <<
"]" << std::endl;
402 template <
typename S>
405 return 0.5 * (i_[0] + i_[1]);
409 template <
typename S>
416 template <
typename S>
420 if(v < res.i_[0]) res.i_[0] = v;
421 if(v > res.i_[1]) res.i_[1] = v;
426 template <
typename S>
430 if(other.i_[0] < res.i_[0]) res.i_[0] = other.i_[0];
431 if(other.i_[1] > res.i_[1]) res.i_[1] = other.i_[1];
Interval & bound(S v)
Compute the minimum interval contains v and original interval.
Definition: interval-inl.h:378
Main namespace.
Definition: broadphase_bruteforce-inl.h:45
S getAbsUpper() const
Return the farthest distance for points within the interval to zero.
Definition: interval-inl.h:361
Interval class for [a, b].
Definition: interval.h:50
bool overlap(const Interval &other) const
determine whether the intersection between intervals is empty
Definition: interval-inl.h:325
S getAbsLower() const
Return the nearest distance for points within the interval to zero.
Definition: interval-inl.h:352
void setValue(S a, S b)
construct interval [left, right]
Definition: interval-inl.h:82
Interval operator/(const Interval &other) const
other must not contain 0
Definition: interval-inl.h:310
S operator[](size_t i) const
access the interval endpoints: 0 for left, 1 for right end
Definition: interval-inl.h:96
bool operator==(const Interval &other) const
whether two intervals are the same
Definition: interval-inl.h:110
Interval operator+(const Interval &other) const
add two intervals
Definition: interval-inl.h:119