@@ -18,7 +18,7 @@ namespace opentime {
18
18
*/
19
19
20
20
/* *
21
- * This default epsilon value is used in comparison between floating numbers.
21
+ * This default epsilon_s value is used in comparison between floating numbers.
22
22
* It is computed to be twice 192khz, the fastest commonly used audio rate.
23
23
* It can be changed in the future if necessary due to higher sampling rates
24
24
* or some other kind of numeric tolerance detected in the library.
@@ -92,8 +92,9 @@ class TimeRange {
92
92
*/
93
93
94
94
/* *
95
- * In the relations that follow, epsilon indicates the tolerance,in the sense that if abs(a-b) < epsilon,
96
- * we consider a and b to be equal
95
+ * In the relations that follow, epsilon_s indicates the tolerance,in the sense that if abs(a-b) < epsilon_s,
96
+ * we consider a and b to be equal.
97
+ * The time comparison is done in double seconds.
97
98
*/
98
99
99
100
/* *
@@ -117,12 +118,12 @@ class TimeRange {
117
118
* The converse would be <em>other.contains(this)</em>
118
119
* @param other
119
120
*/
120
- bool contains (TimeRange other, double epsilon = DEFAULT_EPSILON_s) const {
121
- double thisStart = _start_time.to_seconds ();
122
- double thisEnd = end_time_exclusive ().to_seconds ();
123
- double otherStart = other._start_time .to_seconds ();
124
- double otherEnd = other.end_time_exclusive ().to_seconds ();
125
- return otherStart - thisStart >= epsilon && thisEnd - otherEnd >=epsilon ;
121
+ bool contains (TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const {
122
+ double thisStart = _start_time.to_seconds ();
123
+ double thisEnd = end_time_exclusive ().to_seconds ();
124
+ double otherStart = other._start_time .to_seconds ();
125
+ double otherEnd = other.end_time_exclusive ().to_seconds ();
126
+ return greater_than ( otherStart, thisStart, epsilon_s) && lesser_than ( otherEnd, thisEnd, epsilon_s) ;
126
127
}
127
128
128
129
/* *
@@ -138,49 +139,49 @@ class TimeRange {
138
139
}
139
140
140
141
/* *
141
- * The start of <b>this</b> strictly precedes end of <b>other</b> by a value >= <b>epsilon </b>.
142
- * The end of <b>this</b> strictly antecedes start of <b>other</b> by a value >= <b>epsilon </b>.
142
+ * The start of <b>this</b> strictly precedes end of <b>other</b> by a value >= <b>epsilon_s </b>.
143
+ * The end of <b>this</b> strictly antecedes start of <b>other</b> by a value >= <b>epsilon_s </b>.
143
144
* [ this ]
144
145
* [ other ]
145
146
* The converse would be <em>other.overlaps(this)</em>
146
147
* @param other
147
- * @param epsilon
148
+ * @param epsilon_s
148
149
*/
149
- bool overlaps (TimeRange other, double epsilon = DEFAULT_EPSILON_s) const {
150
- double thisStart = _start_time.to_seconds ();
151
- double thisEnd = end_time_exclusive ().to_seconds ();
152
- double otherStart = other._start_time .to_seconds ();
153
- double otherEnd = other.end_time_exclusive ().to_seconds ();
154
- return (otherEnd - thisEnd >= epsilon ) &&
155
- (otherStart - thisStart >= epsilon ) &&
156
- (thisEnd - otherStart >= epsilon );
150
+ bool overlaps (TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const {
151
+ double thisStart = _start_time.to_seconds ();
152
+ double thisEnd = end_time_exclusive ().to_seconds ();
153
+ double otherStart = other._start_time .to_seconds ();
154
+ double otherEnd = other.end_time_exclusive ().to_seconds ();
155
+ return lesser_than (thisStart, otherStart, epsilon_s ) &&
156
+ greater_than (thisEnd, otherStart, epsilon_s ) &&
157
+ greater_than (otherEnd, thisEnd, epsilon_s );
157
158
}
158
159
159
160
/* *
160
- * The end of <b>this</b> strictly precedes the start of <b>other</b> by a value >= <b>epsilon </b>.
161
+ * The end of <b>this</b> strictly precedes the start of <b>other</b> by a value >= <b>epsilon_s </b>.
161
162
* [ this ] [ other ]
162
163
* The converse would be <em>other.before(this)</em>
163
164
* @param other
164
- * @param epsilon
165
+ * @param epsilon_s
165
166
*/
166
- bool before (TimeRange other, double epsilon = DEFAULT_EPSILON_s) const {
167
+ bool before (TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const {
167
168
double thisEnd = end_time_exclusive ().to_seconds ();
168
169
double otherStart = other._start_time .to_seconds ();
169
- return otherStart - thisEnd >= epsilon ;
170
+ return greater_than ( otherStart, thisEnd, epsilon_s) ;
170
171
}
171
172
172
173
/* *
173
- * The end of <b>this</b> strictly precedes <b>other</b> by a value >= <b>epsilon </b>.
174
+ * The end of <b>this</b> strictly precedes <b>other</b> by a value >= <b>epsilon_s </b>.
174
175
* other
175
176
* ↓
176
177
* [ this ] *
177
178
* @param other
178
- * @param epsilon
179
+ * @param epsilon_s
179
180
*/
180
- bool before (RationalTime other, double epsilon = DEFAULT_EPSILON_s) const {
181
+ bool before (RationalTime other, double epsilon_s = DEFAULT_EPSILON_s) const {
181
182
double thisEnd = end_time_exclusive ().to_seconds ();
182
183
double otherTime = other.to_seconds ();
183
- return otherTime - thisEnd >= epsilon ;
184
+ return lesser_than ( thisEnd, otherTime, epsilon_s) ;
184
185
}
185
186
186
187
/* *
@@ -189,29 +190,29 @@ class TimeRange {
189
190
* [this][other]
190
191
* The converse would be <em>other.meets(this)</em>
191
192
* @param other
192
- * @param epsilon
193
+ * @param epsilon_s
193
194
*/
194
- bool meets (TimeRange other, double epsilon = DEFAULT_EPSILON_s) const {
195
+ bool meets (TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const {
195
196
double thisEnd = end_time_exclusive ().to_seconds ();
196
197
double otherStart = other._start_time .to_seconds ();
197
- return otherStart - thisEnd <= epsilon && otherStart - thisEnd >= 0 ;
198
+ return otherStart - thisEnd <= epsilon_s && otherStart - thisEnd >= 0 ;
198
199
}
199
200
200
201
/* *
201
202
* The start of <b>this</b> strictly equals the start of <b>other</b>.
202
- * The end of <b>this</b> strictly precedes the end of <b>other</b> by a value >= <b>epsilon </b>.
203
+ * The end of <b>this</b> strictly precedes the end of <b>other</b> by a value >= <b>epsilon_s </b>.
203
204
* [ this ]
204
205
* [ other ]
205
206
* The converse would be <em>other.begins(this)</em>
206
207
* @param other
207
- * @param epsilon
208
+ * @param epsilon_s
208
209
*/
209
- bool begins (TimeRange other, double epsilon = DEFAULT_EPSILON_s) const {
210
+ bool begins (TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const {
210
211
double thisStart = _start_time.to_seconds ();
211
212
double thisEnd = end_time_exclusive ().to_seconds ();
212
213
double otherStart = other._start_time .to_seconds ();
213
214
double otherEnd = other.end_time_exclusive ().to_seconds ();
214
- return fabs (otherStart - thisStart) <= epsilon && otherEnd - thisEnd >= epsilon ;
215
+ return fabs (otherStart - thisStart) <= epsilon_s && lesser_than ( thisEnd, otherEnd, epsilon_s) ;
215
216
}
216
217
217
218
/* *
@@ -222,27 +223,27 @@ class TimeRange {
222
223
* [ this ]
223
224
* @param other
224
225
*/
225
- bool begins (RationalTime other, double epsilon = DEFAULT_EPSILON_s) const {
226
+ bool begins (RationalTime other, double epsilon_s = DEFAULT_EPSILON_s) const {
226
227
double thisStart = _start_time.to_seconds ();
227
228
double otherStart = other.to_seconds ();
228
- return fabs (otherStart - thisStart) <= epsilon ;
229
+ return fabs (otherStart - thisStart) <= epsilon_s ;
229
230
}
230
231
231
232
/* *
232
- * The start of <b>this</b> strictly antecedes the start of <b>other</b> by a value >= <b>epsilon </b>.
233
+ * The start of <b>this</b> strictly antecedes the start of <b>other</b> by a value >= <b>epsilon_s </b>.
233
234
* The end of <b>this</b> strictly equals the end of <b>other</b>.
234
235
* [ this ]
235
236
* [ other ]
236
237
* The converse would be <em>other.finishes(this)</em>
237
238
* @param other
238
- * @param epsilon
239
+ * @param epsilon_s
239
240
*/
240
- bool finishes (TimeRange other, double epsilon = DEFAULT_EPSILON_s) const {
241
+ bool finishes (TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const {
241
242
double thisStart = _start_time.to_seconds ();
242
243
double thisEnd = end_time_exclusive ().to_seconds ();
243
244
double otherStart = other._start_time .to_seconds ();
244
245
double otherEnd = other.end_time_exclusive ().to_seconds ();
245
- return fabs (thisEnd - otherEnd) <= epsilon && thisStart - otherStart >= epsilon ;
246
+ return fabs (thisEnd - otherEnd) <= epsilon_s && greater_than ( thisStart, otherStart, epsilon_s) ;
246
247
}
247
248
248
249
/* *
@@ -252,12 +253,29 @@ class TimeRange {
252
253
* *
253
254
* [ this ]
254
255
* @param other
255
- * @param epsilon
256
+ * @param epsilon_s
256
257
*/
257
- bool finishes (RationalTime other, double epsilon = DEFAULT_EPSILON_s) const {
258
+ bool finishes (RationalTime other, double epsilon_s = DEFAULT_EPSILON_s) const {
258
259
double thisEnd = end_time_exclusive ().to_seconds ();
259
260
double otherEnd = other.to_seconds ();
260
- return fabs (thisEnd - otherEnd) <= epsilon;
261
+ return fabs (thisEnd - otherEnd) <= epsilon_s;
262
+ }
263
+
264
+ /* *
265
+ * The start of <b>this</b> precedes or equals the end of <b>other</b> by a value >= <b>epsilon_s</b>.
266
+ * The end of <b>this</b> antecedes or equals the start of <b>other</b> by a value >= <b>epsilon_s</b>.
267
+ * [ this ] OR [ other ]
268
+ * [ other ] [ this ]
269
+ * The converse would be <em>other.finishes(this)</em>
270
+ * @param other
271
+ * @param epsilon_s
272
+ */
273
+ bool intersects (TimeRange other, double epsilon_s = DEFAULT_EPSILON_s) const {
274
+ double thisStart = _start_time.to_seconds ();
275
+ double thisEnd = end_time_exclusive ().to_seconds ();
276
+ double otherStart = other._start_time .to_seconds ();
277
+ double otherEnd = other.end_time_exclusive ().to_seconds ();
278
+ return lesser_than (thisStart, otherEnd, epsilon_s) && greater_than (thisEnd, otherStart, epsilon_s);
261
279
}
262
280
263
281
@@ -293,6 +311,14 @@ class TimeRange {
293
311
private:
294
312
RationalTime _start_time, _duration;
295
313
friend class TimeTransform ;
314
+
315
+ inline constexpr bool greater_than (double lhs, double rhs, double epsilon) const {
316
+ return lhs - rhs >= epsilon;
317
+ }
318
+
319
+ inline constexpr bool lesser_than (double lhs, double rhs, double epsilon) const {
320
+ return rhs - lhs >= epsilon;
321
+ }
296
322
};
297
323
298
324
} }
0 commit comments