FCL  0.6.0
Flexible Collision Library
interval.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2016, Open Source Robotics Foundation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Open Source Robotics Foundation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 // This code is based on code developed by Stephane Redon at UNC and Inria for the CATCH library: http://graphics.ewha.ac.kr/CATCH/
39 #ifndef FCL_CCD_INTERVAL_H
40 #define FCL_CCD_INTERVAL_H
41 
42 #include <iostream>
43 #include "fcl/common/types.h"
44 
45 namespace fcl
46 {
47 
49 template <typename S>
50 struct Interval
51 {
52  S i_[2];
53 
54  Interval();
55 
56  explicit Interval(S v);
57 
59  Interval(S left, S right);
60 
62  void setValue(S a, S b);
63 
65  void setValue(S x);
66 
68  S operator [] (size_t i) const;
69 
71  S& operator [] (size_t i);
72 
74  bool operator == (const Interval& other) const;
75 
77  Interval operator + (const Interval& other) const;
78 
80  Interval operator - (const Interval& other) const;
81 
82  Interval& operator += (const Interval& other);
83 
84  Interval& operator -= (const Interval& other);
85 
86  Interval operator * (const Interval& other) const;
87 
88  Interval& operator *= (const Interval& other);
89 
90  Interval operator * (S d) const;
91 
92  Interval& operator *= (S d);
93 
95  Interval operator / (const Interval& other) const;
96 
97  Interval& operator /= (const Interval& other);
98 
100  bool overlap(const Interval& other) const;
101 
102  bool intersect(const Interval& other);
103 
104  Interval operator - () const;
105 
107  S getAbsLower() const;
108 
110  S getAbsUpper() const;
111 
112  bool contains(S v) const;
113 
115  Interval& bound(S v);
116 
118  Interval& bound(const Interval& other);
119 
120  void print() const;
121 
122  S center() const;
123 
124  S diameter() const;
125 };
126 
127 template <typename S>
128 Interval<S> bound(const Interval<S>& i, S v);
129 
130 template <typename S>
131 Interval<S> bound(const Interval<S>& i, const Interval<S>& other);
132 
133 } // namespace fcl
134 
135 #include "fcl/math/motion/taylor_model/interval-inl.h"
136 
137 #endif
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