• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

estebanzimanyi / MobilityDB / 7150863270

09 Dec 2023 11:29AM UTC coverage: 95.182% (-0.002%) from 95.184%
7150863270

push

github

estebanzimanyi
Improve span ops

1145 of 1171 new or added lines in 71 files covered. (97.78%)

26 existing lines in 6 files now uncovered.

30997 of 32566 relevant lines covered (95.18%)

771477.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.15
/mobilitydb/src/general/tbox.c
1
/*****************************************************************************
2
 *
3
 * This MobilityDB code is provided under The PostgreSQL License.
4
 * Copyright (c) 2016-2023, Université libre de Bruxelles and MobilityDB
5
 * contributors
6
 *
7
 * MobilityDB includes portions of PostGIS version 3 source code released
8
 * under the GNU General Public License (GPLv2 or later).
9
 * Copyright (c) 2001-2023, PostGIS contributors
10
 *
11
 * Permission to use, copy, modify, and distribute this software and its
12
 * documentation for any purpose, without fee, and without a written
13
 * agreement is hereby granted, provided that the above copyright notice and
14
 * this paragraph and the following two paragraphs appear in all copies.
15
 *
16
 * IN NO EVENT SHALL UNIVERSITE LIBRE DE BRUXELLES BE LIABLE TO ANY PARTY FOR
17
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
18
 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
19
 * EVEN IF UNIVERSITE LIBRE DE BRUXELLES HAS BEEN ADVISED OF THE POSSIBILITY
20
 * OF SUCH DAMAGE.
21
 *
22
 * UNIVERSITE LIBRE DE BRUXELLES SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON
25
 * AN "AS IS" BASIS, AND UNIVERSITE LIBRE DE BRUXELLES HAS NO OBLIGATIONS TO
26
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27
 *
28
 *****************************************************************************/
29

30
/**
31
 * @file
32
 * @brief Functions for temporal bounding boxes.
33
 */
34

35
#include "general/tbox.h"
36

37
/* C */
38
#include <assert.h>
39
/* PostgreSQL */
40
#include <utils/timestamp.h>
41
/* MEOS */
42
#include <meos.h>
43
#include <meos_internal.h>
44
#include "general/set.h"
45
#include "general/temporal.h"
46
#include "general/tnumber_mathfuncs.h"
47
#include "general/type_out.h"
48
#include "general/type_util.h"
49
/* MobilityDB */
50
#include "pg_general/meos_catalog.h"
51
#include "pg_general/temporal.h"
52
#include "pg_general/type_util.h"
53

54
/*****************************************************************************
55
 * Input/output functions
56
 *****************************************************************************/
57

58
PGDLLEXPORT Datum Tbox_in(PG_FUNCTION_ARGS);
59
PG_FUNCTION_INFO_V1(Tbox_in);
7✔
60
/**
61
 * @ingroup mobilitydb_box_inout
62
 * @brief Input function for temporal boxes.
63
 *
64
 * Examples of input:
65
 * @code
66
 * TBOX((1.0, 2.0), (1.0, 2.0))   -- Both X and T dimensions
67
 * TBOX((1.0, ), (1.0, ))      -- Only X dimension
68
 * TBOX((, 2.0), (, 2.0))      -- Only T dimension
69
 * @endcode
70
 * where the commas are optional
71
 * @sqlfunc tbox_in()
72
 */
73
Datum
74
Tbox_in(PG_FUNCTION_ARGS)
661✔
75
{
76
  const char *input = PG_GETARG_CSTRING(0);
661✔
77
  PG_RETURN_POINTER(tbox_in(input));
661✔
78
}
79

80
PGDLLEXPORT Datum Tbox_out(PG_FUNCTION_ARGS);
81
PG_FUNCTION_INFO_V1(Tbox_out);
6✔
82
/**
83
 * @ingroup mobilitydb_box_inout
84
 * @brief Output function for temporal boxes.
85
 * @sqlfunc tbox_out()
86
 */
87
Datum
88
Tbox_out(PG_FUNCTION_ARGS)
85✔
89
{
90
  TBox *box = PG_GETARG_TBOX_P(0);
85✔
91
  PG_RETURN_CSTRING(tbox_out(box, OUT_DEFAULT_DECIMAL_DIGITS));
85✔
92
}
93

94
PGDLLEXPORT Datum Tbox_recv(PG_FUNCTION_ARGS);
95
PG_FUNCTION_INFO_V1(Tbox_recv);
2✔
96
/**
97
 * @ingroup mobilitydb_box_inout
98
 * @brief Receive function for TBox
99
 * @sqlfunc tbox_recv()
100
 */
101
Datum
102
Tbox_recv(PG_FUNCTION_ARGS)
198✔
103
{
104
  StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
198✔
105
  TBox *result = tbox_from_wkb((uint8_t *) buf->data, buf->len);
198✔
106
  /* Set cursor to the end of buffer (so the backend is happy) */
107
  buf->cursor = buf->len;
198✔
108
  PG_RETURN_POINTER(result);
198✔
109
}
110

111
PGDLLEXPORT Datum Tbox_send(PG_FUNCTION_ARGS);
112
PG_FUNCTION_INFO_V1(Tbox_send);
2✔
113
/**
114
 * @ingroup mobilitydb_box_inout
115
 * @brief Send function for TBox
116
 * @sqlfunc tbox_send()
117
 */
118
Datum
119
Tbox_send(PG_FUNCTION_ARGS)
198✔
120
{
121
  TBox *box = PG_GETARG_TBOX_P(0);
198✔
122
  uint8_t variant = 0;
123
  size_t wkb_size;
124
  uint8_t *wkb = tbox_as_wkb(box, variant, &wkb_size);
198✔
125
  bytea *result = bstring2bytea(wkb, wkb_size);
198✔
126
  pfree(wkb);
198✔
127
  PG_RETURN_BYTEA_P(result);
198✔
128
}
129

130
/*****************************************************************************
131
 * Output in WKT format
132
 *****************************************************************************/
133

134
PGDLLEXPORT Datum Tbox_as_text(PG_FUNCTION_ARGS);
135
PG_FUNCTION_INFO_V1(Tbox_as_text);
2✔
136
/**
137
 * @ingroup mobilitydb_box_inout
138
 * @brief Output function for temporal boxes.
139
 * @sqlfunc asText()
140
 */
141
Datum
142
Tbox_as_text(PG_FUNCTION_ARGS)
1✔
143
{
144
  TBox *box = PG_GETARG_TBOX_P(0);
1✔
145
  int dbl_dig_for_wkt = OUT_DEFAULT_DECIMAL_DIGITS;
146
  if (PG_NARGS() > 1 && ! PG_ARGISNULL(1))
1✔
147
    dbl_dig_for_wkt = PG_GETARG_INT32(1);
1✔
148
  char *str = tbox_out(box, dbl_dig_for_wkt);
1✔
149
  text *result = cstring2text(str);
1✔
150
  pfree(str);
1✔
151
  PG_RETURN_TEXT_P(result);
1✔
152
}
153

154
/*****************************************************************************
155
 * Constructor functions
156
 *****************************************************************************/
157

158
PGDLLEXPORT Datum Number_timestamptz_to_tbox(PG_FUNCTION_ARGS);
159
PG_FUNCTION_INFO_V1(Number_timestamptz_to_tbox);
4✔
160
/**
161
 * @ingroup mobilitydb_box_constructor
162
 * @brief Transform the integer and the timestamp to a temporal box
163
 * @sqlfunc tbox()
164
 */
165
Datum
166
Number_timestamptz_to_tbox(PG_FUNCTION_ARGS)
19,602✔
167
{
168
  Datum d = PG_GETARG_DATUM(0);
19,602✔
169
  TimestampTz t = PG_GETARG_TIMESTAMPTZ(1);
19,602✔
170
  meosType basetype = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 0));
19,602✔
171
  TBox *result = number_timestamptz_to_tbox(d, basetype, t);
19,602✔
172
  PG_RETURN_POINTER(result);
19,602✔
173
}
174

175
PGDLLEXPORT Datum Number_tstzspan_to_tbox(PG_FUNCTION_ARGS);
176
PG_FUNCTION_INFO_V1(Number_tstzspan_to_tbox);
4✔
177
/**
178
 * @ingroup mobilitydb_box_constructor
179
 * @brief  Transform an integer and a timestamptz span to a temporal box
180
 * @sqlfunc tbox()
181
 */
182
Datum
183
Number_tstzspan_to_tbox(PG_FUNCTION_ARGS)
19,602✔
184
{
185
  Datum d = PG_GETARG_DATUM(0);
19,602✔
186
  Span *s = PG_GETARG_SPAN_P(1);
19,602✔
187
  meosType basetype = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 0));
19,602✔
188
  TBox *result = number_tstzspan_to_tbox(d, basetype, s);
19,602✔
189
  PG_RETURN_POINTER(result);
19,602✔
190
}
191

192
PGDLLEXPORT Datum Numnumspan_timestamptz_to_tbox(PG_FUNCTION_ARGS);
193
PG_FUNCTION_INFO_V1(Numnumspan_timestamptz_to_tbox);
5✔
194
/**
195
 * @ingroup mobilitydb_box_constructor
196
 * @brief Transform the span and the timestamp to a temporal box
197
 * @sqlfunc tbox()
198
 */
199
Datum
200
Numnumspan_timestamptz_to_tbox(PG_FUNCTION_ARGS)
19,603✔
201
{
202
  Span *span = PG_GETARG_SPAN_P(0);
19,603✔
203
  TimestampTz t = PG_GETARG_TIMESTAMPTZ(1);
19,603✔
204
  TBox *result = numspan_timestamptz_to_tbox(span, t);
19,603✔
205
  PG_RETURN_POINTER(result);
19,603✔
206
}
207

208
PGDLLEXPORT Datum Numspan_tstzspan_to_tbox(PG_FUNCTION_ARGS);
209
PG_FUNCTION_INFO_V1(Numspan_tstzspan_to_tbox);
5✔
210
/**
211
 * @ingroup mobilitydb_box_constructor
212
 * @brief Transform the span and the period to a temporal box
213
 * @sqlfunc tbox()
214
 */
215
Datum
216
Numspan_tstzspan_to_tbox(PG_FUNCTION_ARGS)
19,603✔
217
{
218
  Span *s = PG_GETARG_SPAN_P(0);
19,603✔
219
  Span *p = PG_GETARG_SPAN_P(1);
19,603✔
220
  TBox *result = numspan_tstzspan_to_tbox(s, p);
19,603✔
221
  PG_RETURN_POINTER(result);
19,603✔
222
}
223

224
/*****************************************************************************
225
 * Conversion functions
226
 *****************************************************************************/
227

228
PGDLLEXPORT Datum Number_to_tbox(PG_FUNCTION_ARGS);
229
PG_FUNCTION_INFO_V1(Number_to_tbox);
7✔
230
/**
231
 * @ingroup mobilitydb_box_conversion
232
 * @brief Convert a number to a temporal box
233
 * @sqlfunc tbox()
234
 */
235
Datum
236
Number_to_tbox(PG_FUNCTION_ARGS)
215✔
237
{
238
  Datum d = PG_GETARG_DATUM(0);
215✔
239
  meosType basetype = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 0));
215✔
240
  TBox *result = number_to_tbox(d, basetype);
215✔
241
  PG_RETURN_POINTER(result);
215✔
242
}
243

244
PGDLLEXPORT Datum Numeric_to_tbox(PG_FUNCTION_ARGS);
245
PG_FUNCTION_INFO_V1(Numeric_to_tbox);
2✔
246
/**
247
 * @ingroup mobilitydb_box_conversion
248
 * @brief Transform the numeric to a temporal box
249
 * @sqlfunc tbox()
250
 */
251
Datum
252
Numeric_to_tbox(PG_FUNCTION_ARGS)
1✔
253
{
254
  Datum num = PG_GETARG_DATUM(0);
1✔
255
  Datum d = call_function1(numeric_float8, num);
1✔
256
  TBox *result = number_to_tbox(d, T_FLOAT8);
1✔
257
  PG_RETURN_POINTER(result);
1✔
258
}
259

260
PGDLLEXPORT Datum Timestamptz_to_tbox(PG_FUNCTION_ARGS);
261
PG_FUNCTION_INFO_V1(Timestamptz_to_tbox);
3✔
262
/**
263
 * @ingroup mobilitydb_box_conversion
264
 * @brief Transform the timestamp to a temporal box
265
 * @sqlfunc tbox()
266
 */
267
Datum
268
Timestamptz_to_tbox(PG_FUNCTION_ARGS)
100✔
269
{
270
  TimestampTz t = PG_GETARG_TIMESTAMPTZ(0);
100✔
271
  TBox *result = timestamptz_to_tbox(t);
100✔
272
  PG_RETURN_POINTER(result);
100✔
273
}
274

275
PGDLLEXPORT Datum Set_to_tbox(PG_FUNCTION_ARGS);
276
PG_FUNCTION_INFO_V1(Set_to_tbox);
7✔
277
/**
278
 * @ingroup mobilitydb_box_conversion
279
 * @brief Transform the set to a temporal box
280
 * @sqlfunc tbox()
281
 */
282
Datum
283
Set_to_tbox(PG_FUNCTION_ARGS)
102✔
284
{
285
  Set *s = PG_GETARG_SET_P(0);
102✔
286
  TBox *result;
287
  if (numset_type(s->settype))
102✔
288
    result = numset_to_tbox(s);
2✔
289
  else
290
    result = tstzset_to_tbox(s);
100✔
291
  PG_FREE_IF_COPY_P(s, 0);
102✔
292
  PG_RETURN_POINTER(result);
102✔
293
}
294

295
PGDLLEXPORT Datum Span_to_tbox(PG_FUNCTION_ARGS);
296
PG_FUNCTION_INFO_V1(Span_to_tbox);
12✔
297
/**
298
 * @ingroup mobilitydb_box_conversion
299
 * @brief Transform the span to a temporal box
300
 * @sqlfunc tbox()
301
 */
302
Datum
303
Span_to_tbox(PG_FUNCTION_ARGS)
310✔
304
{
305
  Span *s = PG_GETARG_SPAN_P(0);
310✔
306
  TBox *result;
307
  if (numspan_type(s->spantype))
310✔
308
    result = numspan_to_tbox(s);
207✔
309
  else
310
    result = tstzspan_to_tbox(s);
103✔
311
  PG_RETURN_POINTER(result);
310✔
312
}
313

314
/**
315
 * @brief Peak into a span set datum to find the bounding box. If the datum
316
 * needs to be detoasted, extract only the header and not the full object.
317
 */
318
void
319
spanset_tbox_slice(Datum ssdatum, TBox *box)
102✔
320
{
321
  SpanSet *ss = NULL;
322
  if (PG_DATUM_NEEDS_DETOAST((struct varlena *) ssdatum))
102✔
323
    ss = (SpanSet *) PG_DETOAST_DATUM_SLICE(ssdatum, 0,
34✔
324
      time_max_header_size());
325
  else
326
    ss = (SpanSet *) ssdatum;
327
  if (numspan_type(ss->span.spantype))
102✔
328
    numspan_set_tbox(&ss->span, box);
2✔
329
  else
330
    tstzspan_set_tbox(&ss->span, box);
100✔
331
  PG_FREE_IF_COPY_P(ss, DatumGetPointer(ssdatum));
102✔
332
  return;
102✔
333
}
334

335
PGDLLEXPORT Datum Spanset_to_tbox(PG_FUNCTION_ARGS);
336
PG_FUNCTION_INFO_V1(Spanset_to_tbox);
7✔
337
/**
338
 * @ingroup mobilitydb_box_conversion
339
 * @brief Transform the span set to a temporal box
340
 * @sqlfunc tbox()
341
 */
342
Datum
343
Spanset_to_tbox(PG_FUNCTION_ARGS)
102✔
344
{
345
  Datum ssdatum = PG_GETARG_DATUM(0);
102✔
346
  TBox *result = palloc(sizeof(TBox));
102✔
347
  spanset_tbox_slice(ssdatum, result);
102✔
348
  PG_RETURN_POINTER(result);
102✔
349
}
350

351
/*****************************************************************************/
352

353
PGDLLEXPORT Datum Tbox_to_floatspan(PG_FUNCTION_ARGS);
354
PG_FUNCTION_INFO_V1(Tbox_to_floatspan);
2✔
355
/**
356
 * @ingroup mobilitydb_box_conversion
357
 * @brief Convert a temporal box as a float span
358
 * @sqlfunc floatspan()
359
 */
360
Datum
361
Tbox_to_floatspan(PG_FUNCTION_ARGS)
201✔
362
{
363
  TBox *box = PG_GETARG_TBOX_P(0);
201✔
364
  Span *result = tbox_to_floatspan(box);
201✔
365
  if (! result)
200✔
366
    PG_RETURN_NULL();
×
367
  PG_RETURN_POINTER(result);
200✔
368
}
369

370
PGDLLEXPORT Datum Tbox_to_tstzspan(PG_FUNCTION_ARGS);
371
PG_FUNCTION_INFO_V1(Tbox_to_tstzspan);
2✔
372
/**
373
 * @ingroup mobilitydb_box_conversion
374
 * @brief Convert a temporal box as a timestamptz span
375
 * @sqlfunc period()
376
 */
377
Datum
378
Tbox_to_tstzspan(PG_FUNCTION_ARGS)
102✔
379
{
380
  TBox *box = PG_GETARG_TBOX_P(0);
102✔
381
  Span *result = tbox_to_tstzspan(box);
102✔
382
  if (! result)
101✔
383
    PG_RETURN_NULL();
×
384
  PG_RETURN_POINTER(result);
101✔
385
}
386

387
/*****************************************************************************
388
 * Accessor functions
389
 *****************************************************************************/
390

391
PGDLLEXPORT Datum Tbox_hasx(PG_FUNCTION_ARGS);
392
PG_FUNCTION_INFO_V1(Tbox_hasx);
2✔
393
/**
394
 * @ingroup mobilitydb_box_accessor
395
 * @brief Return true if a temporal box has value dimension
396
 * @sqlfunc hasX()
397
 */
398
Datum
399
Tbox_hasx(PG_FUNCTION_ARGS)
3✔
400
{
401
  TBox *box = PG_GETARG_TBOX_P(0);
3✔
402
  PG_RETURN_BOOL(tbox_hasx(box));
3✔
403
}
404

405
PGDLLEXPORT Datum Tbox_hast(PG_FUNCTION_ARGS);
406
PG_FUNCTION_INFO_V1(Tbox_hast);
2✔
407
/**
408
 * @ingroup mobilitydb_box_accessor
409
 * @brief Return true if a temporal box has time dimension
410
 * @sqlfunc hasT()
411
 */
412
Datum
413
Tbox_hast(PG_FUNCTION_ARGS)
3✔
414
{
415
  TBox *box = PG_GETARG_TBOX_P(0);
3✔
416
  PG_RETURN_BOOL(tbox_hast(box));
3✔
417
}
418

419
PGDLLEXPORT Datum Tbox_xmin(PG_FUNCTION_ARGS);
420
PG_FUNCTION_INFO_V1(Tbox_xmin);
2✔
421
/**
422
 * @ingroup mobilitydb_box_accessor
423
 * @brief Return the minimum X value of a temporal box
424
 * @sqlfunc Xmin()
425
 */
426
Datum
427
Tbox_xmin(PG_FUNCTION_ARGS)
201✔
428
{
429
  TBox *box = PG_GETARG_TBOX_P(0);
201✔
430
  double result;
431
  if (! tbox_xmin(box, &result))
201✔
432
    PG_RETURN_NULL();
1✔
433
  PG_RETURN_FLOAT8(result);
200✔
434
}
435

436
PGDLLEXPORT Datum Tbox_xmin_inc(PG_FUNCTION_ARGS);
437
PG_FUNCTION_INFO_V1(Tbox_xmin_inc);
2✔
438
/**
439
 * @ingroup mobilitydb_box_accessor
440
 * @brief Return true if the minimum X value of a temporal box is inclusive
441
 * @sqlfunc Xmin_inc()
442
 */
443
Datum
444
Tbox_xmin_inc(PG_FUNCTION_ARGS)
2✔
445
{
446
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
447
  bool result;
448
  if (! tbox_xmin_inc(box, &result))
2✔
449
    PG_RETURN_NULL();
1✔
450
  PG_RETURN_BOOL(result);
1✔
451
}
452

453
PGDLLEXPORT Datum Tbox_xmax(PG_FUNCTION_ARGS);
454
PG_FUNCTION_INFO_V1(Tbox_xmax);
2✔
455
/**
456
 * @ingroup mobilitydb_box_accessor
457
 * @brief Return the maximum X value of a temporal box
458
 * @sqlfunc Xmax()
459
 */
460
Datum
461
Tbox_xmax(PG_FUNCTION_ARGS)
597✔
462
{
463
  TBox *box = PG_GETARG_TBOX_P(0);
597✔
464
  double result;
465
  if (! tbox_xmax(box, &result))
597✔
466
    PG_RETURN_NULL();
1✔
467
  PG_RETURN_FLOAT8(result);
596✔
468
}
469

470
PGDLLEXPORT Datum Tbox_xmax_inc(PG_FUNCTION_ARGS);
471
PG_FUNCTION_INFO_V1(Tbox_xmax_inc);
2✔
472
/**
473
 * @ingroup mobilitydb_box_accessor
474
 * @brief Return true if the maximum X value of a temporal box is inclusive
475
 * @sqlfunc Xmin_inc()
476
 */
477
Datum
478
Tbox_xmax_inc(PG_FUNCTION_ARGS)
2✔
479
{
480
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
481
  bool result;
482
  if (! tbox_xmax_inc(box, &result))
2✔
483
    PG_RETURN_NULL();
1✔
484
  PG_RETURN_BOOL(result);
1✔
485
}
486

487
PGDLLEXPORT Datum Tbox_tmin(PG_FUNCTION_ARGS);
488
PG_FUNCTION_INFO_V1(Tbox_tmin);
2✔
489
/**
490
 * @ingroup mobilitydb_box_accessor
491
 * @brief Return the minimum timestamp of a temporal box
492
 * @sqlfunc Tmin()
493
 */
494
Datum
495
Tbox_tmin(PG_FUNCTION_ARGS)
201✔
496
{
497
  TBox *box = PG_GETARG_TBOX_P(0);
201✔
498
  TimestampTz result;
499
  if (! tbox_tmin(box, &result))
201✔
500
    PG_RETURN_NULL();
1✔
501
  PG_RETURN_TIMESTAMPTZ(result);
200✔
502
}
503

504
PGDLLEXPORT Datum Tbox_tmin_inc(PG_FUNCTION_ARGS);
505
PG_FUNCTION_INFO_V1(Tbox_tmin_inc);
2✔
506
/**
507
 * @ingroup mobilitydb_box_accessor
508
 * @brief Return true if the minimum timestamp value of a temporal box is
509
 * inclusive
510
 * @sqlfunc Tmin_inc()
511
 */
512
Datum
513
Tbox_tmin_inc(PG_FUNCTION_ARGS)
2✔
514
{
515
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
516
  bool result;
517
  if (! tbox_tmin_inc(box, &result))
2✔
518
    PG_RETURN_NULL();
1✔
519
  PG_RETURN_BOOL(result);
1✔
520
}
521

522
PGDLLEXPORT Datum Tbox_tmax(PG_FUNCTION_ARGS);
523
PG_FUNCTION_INFO_V1(Tbox_tmax);
2✔
524
/**
525
 * @ingroup mobilitydb_box_accessor
526
 * @brief Return the maximum timestamp of a temporal box
527
 * @sqlfunc Tmax()
528
 */
529
Datum
530
Tbox_tmax(PG_FUNCTION_ARGS)
201✔
531
{
532
  TBox *box = PG_GETARG_TBOX_P(0);
201✔
533
  TimestampTz result;
534
  if (! tbox_tmax(box, &result))
201✔
535
    PG_RETURN_NULL();
1✔
536
  PG_RETURN_TIMESTAMPTZ(result);
200✔
537
}
538

539
PGDLLEXPORT Datum Tbox_tmax_inc(PG_FUNCTION_ARGS);
540
PG_FUNCTION_INFO_V1(Tbox_tmax_inc);
2✔
541
/**
542
 * @ingroup mobilitydb_box_accessor
543
 * @brief Return true if the maximum timestamp value of a temporal box is
544
 * inclusive
545
 * @sqlfunc Tmin_inc()
546
 */
547
Datum
548
Tbox_tmax_inc(PG_FUNCTION_ARGS)
2✔
549
{
550
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
551
  bool result;
552
  if (! tbox_tmax_inc(box, &result))
2✔
553
    PG_RETURN_NULL();
1✔
554
  PG_RETURN_BOOL(result);
1✔
555
}
556

557
/*****************************************************************************
558
 * Transformation functions
559
 *****************************************************************************/
560

561
PGDLLEXPORT Datum Tbox_shift_value(PG_FUNCTION_ARGS);
562
PG_FUNCTION_INFO_V1(Tbox_shift_value);
3✔
563
/**
564
 * @ingroup mobilitydb_setspan_transf
565
 * @brief Shift the value span of the temporal box by the value
566
 * @sqlfunc shiftValue()
567
 */
568
Datum
569
Tbox_shift_value(PG_FUNCTION_ARGS)
2✔
570
{
571
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
572
  Datum shift = PG_GETARG_DATUM(1);
2✔
573
  meosType basetype = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 1));
2✔
574
  ensure_span_isof_basetype(&box->span, basetype);
2✔
575
  TBox *result = tbox_shift_scale_value(box, shift, 0, true, false);
2✔
576
  PG_RETURN_POINTER(result);
2✔
577
}
578

579
PGDLLEXPORT Datum Tbox_shift_time(PG_FUNCTION_ARGS);
580
PG_FUNCTION_INFO_V1(Tbox_shift_time);
2✔
581
/**
582
 * @ingroup mobilitydb_setspan_transf
583
 * @brief Shift the period of the temporal box by the interval
584
 * @sqlfunc shiftTime()
585
 */
586
Datum
587
Tbox_shift_time(PG_FUNCTION_ARGS)
2✔
588
{
589
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
590
  Interval *shift = PG_GETARG_INTERVAL_P(1);
2✔
591
  TBox *result = tbox_shift_scale_time(box, shift, NULL);
2✔
592
  PG_RETURN_POINTER(result);
2✔
593
}
594

595
PGDLLEXPORT Datum Tbox_scale_value(PG_FUNCTION_ARGS);
596
PG_FUNCTION_INFO_V1(Tbox_scale_value);
3✔
597
/**
598
 * @ingroup mobilitydb_setspan_transf
599
 * @brief Scale the value span of the temporal box by the value
600
 * @sqlfunc scaleValue()
601
 */
602
Datum
603
Tbox_scale_value(PG_FUNCTION_ARGS)
2✔
604
{
605
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
606
  Datum width = PG_GETARG_DATUM(1);
2✔
607
  meosType basetype = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 1));
2✔
608
  ensure_span_isof_basetype(&box->span, basetype);
2✔
609
  TBox *result = tbox_shift_scale_value(box, 0, width, false, true);
2✔
610
  PG_RETURN_POINTER(result);
1✔
611
}
612

613
PGDLLEXPORT Datum Tbox_scale_time(PG_FUNCTION_ARGS);
614
PG_FUNCTION_INFO_V1(Tbox_scale_time);
2✔
615
/**
616
 * @ingroup mobilitydb_setspan_transf
617
 * @brief Scale the period of the temporal box by the interval
618
 * @sqlfunc scaleTime()
619
 */
620
Datum
621
Tbox_scale_time(PG_FUNCTION_ARGS)
3✔
622
{
623
  TBox *box = PG_GETARG_TBOX_P(0);
3✔
624
  Interval *duration = PG_GETARG_INTERVAL_P(1);
3✔
625
  TBox *result = tbox_shift_scale_time(box, NULL, duration);
3✔
626
  PG_RETURN_POINTER(result);
2✔
627
}
628

629
PGDLLEXPORT Datum Tbox_shift_scale_value(PG_FUNCTION_ARGS);
630
PG_FUNCTION_INFO_V1(Tbox_shift_scale_value);
3✔
631
/**
632
 * @ingroup mobilitydb_setspan_transf
633
 * @brief Shift and scale the value span of the temporal box by the values
634
 * @sqlfunc scaleValue()
635
 */
636
Datum
637
Tbox_shift_scale_value(PG_FUNCTION_ARGS)
2✔
638
{
639
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
640
  Datum shift = PG_GETARG_DATUM(1);
2✔
641
  Datum width = PG_GETARG_DATUM(2);
2✔
642
  meosType basetype1 = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 1));
2✔
643
  meosType basetype2 = oid_type(get_fn_expr_argtype(fcinfo->flinfo, 2));
2✔
644
  ensure_span_isof_basetype(&box->span, basetype1);
2✔
645
  ensure_span_isof_basetype(&box->span, basetype2);
2✔
646
  TBox *result = tbox_shift_scale_value(box, shift, width, true, true);
2✔
647
  PG_RETURN_POINTER(result);
2✔
648
}
649

650
PGDLLEXPORT Datum Tbox_shift_scale_time(PG_FUNCTION_ARGS);
651
PG_FUNCTION_INFO_V1(Tbox_shift_scale_time);
2✔
652
/**
653
 * @ingroup mobilitydb_setspan_transf
654
 * @brief Shift and scale the period of the temporal box by the intervals
655
 * @sqlfunc shiftScaleTime()
656
 */
657
Datum
658
Tbox_shift_scale_time(PG_FUNCTION_ARGS)
2✔
659
{
660
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
661
  Interval *shift = PG_GETARG_INTERVAL_P(1);
2✔
662
  Interval *duration = PG_GETARG_INTERVAL_P(2);
2✔
663
  TBox *result = tbox_shift_scale_time(box, shift, duration);
2✔
664
  PG_RETURN_POINTER(result);
2✔
665
}
666

667
PGDLLEXPORT Datum Tbox_expand_int(PG_FUNCTION_ARGS);
668
PG_FUNCTION_INFO_V1(Tbox_expand_int);
2✔
669
/**
670
 * @ingroup mobilitydb_box_transf
671
 * @brief Return a temporal box expanded in the value dimension by an integer
672
 * @sqlfunc expandValue()
673
 */
674
Datum
675
Tbox_expand_int(PG_FUNCTION_ARGS)
3✔
676
{
677
  TBox *box = PG_GETARG_TBOX_P(0);
3✔
678
  int i = PG_GETARG_INT32(1);
3✔
679
  PG_RETURN_POINTER(tbox_expand_int(box, i));
3✔
680
}
681

682
PGDLLEXPORT Datum Tbox_expand_float(PG_FUNCTION_ARGS);
683
PG_FUNCTION_INFO_V1(Tbox_expand_float);
2✔
684
/**
685
 * @ingroup mobilitydb_box_transf
686
 * @brief Return a temporal box expanded in the value dimension by a double
687
 * @sqlfunc expandValue()
688
 */
689
Datum
690
Tbox_expand_float(PG_FUNCTION_ARGS)
1✔
691
{
692
  TBox *box = PG_GETARG_TBOX_P(0);
1✔
693
  double d = PG_GETARG_FLOAT8(1);
1✔
694
  PG_RETURN_POINTER(tbox_expand_float(box, d));
1✔
695
}
696

697
PGDLLEXPORT Datum Tbox_expand_time(PG_FUNCTION_ARGS);
698
PG_FUNCTION_INFO_V1(Tbox_expand_time);
2✔
699
/**
700
 * @ingroup mobilitydb_box_transf
701
 * @brief Return a temporal box expanded in the time dimension by an interval
702
 * @sqlfunc expandTime()
703
 */
704
Datum
705
Tbox_expand_time(PG_FUNCTION_ARGS)
2✔
706
{
707
  TBox *box = PG_GETARG_TBOX_P(0);
2✔
708
  Interval *interval = PG_GETARG_INTERVAL_P(1);
2✔
709
  PG_RETURN_POINTER(tbox_expand_time(box, interval));
2✔
710
}
711

712
PGDLLEXPORT Datum Tbox_round(PG_FUNCTION_ARGS);
713
PG_FUNCTION_INFO_V1(Tbox_round);
3✔
714
/**
715
 * @ingroup mobilitydb_box_transf
716
 * @brief Set the precision of the value dimension of the temporal box to the
717
 * number of decimal places
718
 * @sqlfunc round()
719
 */
720
Datum
721
Tbox_round(PG_FUNCTION_ARGS)
8✔
722
{
723
  TBox *box = PG_GETARG_TBOX_P(0);
8✔
724
  int maxdd = PG_GETARG_INT32(1);
8✔
725
  PG_RETURN_POINTER(tbox_round(box, maxdd));
8✔
726
}
727

728
/*****************************************************************************
729
 * Topological operators
730
 *****************************************************************************/
731

732
PGDLLEXPORT Datum Contains_tbox_tbox(PG_FUNCTION_ARGS);
733
PG_FUNCTION_INFO_V1(Contains_tbox_tbox);
3✔
734
/**
735
 * @ingroup mobilitydb_box_topo
736
 * @brief Return true if the first temporal box contains the second one
737
 * @sqlfunc tbox_contains()
738
 */
739
Datum
740
Contains_tbox_tbox(PG_FUNCTION_ARGS)
39,206✔
741
{
742
  TBox *box1 = PG_GETARG_TBOX_P(0);
39,206✔
743
  TBox *box2 = PG_GETARG_TBOX_P(1);
39,206✔
744
  PG_RETURN_BOOL(contains_tbox_tbox(box1, box2));
39,206✔
745
}
746

747
PGDLLEXPORT Datum Contained_tbox_tbox(PG_FUNCTION_ARGS);
748
PG_FUNCTION_INFO_V1(Contained_tbox_tbox);
3✔
749
/**
750
 * @ingroup mobilitydb_box_topo
751
 * @brief Return true if the first temporal box is contained in the second one
752
 * @sqlfunc tbox_contained()
753
 */
754
Datum
755
Contained_tbox_tbox(PG_FUNCTION_ARGS)
39,206✔
756
{
757
  TBox *box1 = PG_GETARG_TBOX_P(0);
39,206✔
758
  TBox *box2 = PG_GETARG_TBOX_P(1);
39,206✔
759
  PG_RETURN_BOOL(contained_tbox_tbox(box1, box2));
39,206✔
760
}
761

762
PGDLLEXPORT Datum Overlaps_tbox_tbox(PG_FUNCTION_ARGS);
763
PG_FUNCTION_INFO_V1(Overlaps_tbox_tbox);
3✔
764
/**
765
 * @ingroup mobilitydb_box_topo
766
 * @brief Return true if the temporal boxes overlap
767
 * @sqlfunc tbox_overlaps()
768
 */
769
Datum
770
Overlaps_tbox_tbox(PG_FUNCTION_ARGS)
58,808✔
771
{
772
  TBox *box1 = PG_GETARG_TBOX_P(0);
58,808✔
773
  TBox *box2 = PG_GETARG_TBOX_P(1);
58,808✔
774
  PG_RETURN_BOOL(overlaps_tbox_tbox(box1, box2));
58,808✔
775
}
776

777
PGDLLEXPORT Datum Same_tbox_tbox(PG_FUNCTION_ARGS);
778
PG_FUNCTION_INFO_V1(Same_tbox_tbox);
3✔
779
/**
780
 * @ingroup mobilitydb_box_topo
781
 * @brief Return true if the temporal boxes are equal on the common dimensions
782
 * @sqlfunc tbox_same()
783
 */
784
Datum
785
Same_tbox_tbox(PG_FUNCTION_ARGS)
39,206✔
786
{
787
  TBox *box1 = PG_GETARG_TBOX_P(0);
39,206✔
788
  TBox *box2 = PG_GETARG_TBOX_P(1);
39,206✔
789
  PG_RETURN_BOOL(same_tbox_tbox(box1, box2));
39,206✔
790
}
791

792
PGDLLEXPORT Datum Adjacent_tbox_tbox(PG_FUNCTION_ARGS);
793
PG_FUNCTION_INFO_V1(Adjacent_tbox_tbox);
3✔
794
/**
795
 * @ingroup mobilitydb_box_topo
796
 * @brief Return true if the temporal boxes are adjacent
797
 * @sqlfunc tbox_adjacent()
798
 */
799
Datum
800
Adjacent_tbox_tbox(PG_FUNCTION_ARGS)
39,207✔
801
{
802
  TBox *box1 = PG_GETARG_TBOX_P(0);
39,207✔
803
  TBox *box2 = PG_GETARG_TBOX_P(1);
39,207✔
804
  PG_RETURN_BOOL(adjacent_tbox_tbox(box1, box2));
39,207✔
805
}
806

807
/*****************************************************************************
808
 * Position operators
809
 *****************************************************************************/
810

811
PGDLLEXPORT Datum Left_tbox_tbox(PG_FUNCTION_ARGS);
812
PG_FUNCTION_INFO_V1(Left_tbox_tbox);
2✔
813
/**
814
 * @ingroup mobilitydb_box_pos
815
 * @brief Return true if the first temporal box is strictly to the left of the second one
816
 * @sqlfunc tbox_left()
817
 */
818
Datum
819
Left_tbox_tbox(PG_FUNCTION_ARGS)
19,604✔
820
{
821
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,604✔
822
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,604✔
823
  PG_RETURN_BOOL(left_tbox_tbox(box1, box2));
19,604✔
824
}
825

826
PGDLLEXPORT Datum Overleft_tbox_tbox(PG_FUNCTION_ARGS);
827
PG_FUNCTION_INFO_V1(Overleft_tbox_tbox);
2✔
828
/**
829
 * @ingroup mobilitydb_box_pos
830
 * @brief Return true if the first temporal box does not extend to the right of the second one
831
 * @sqlfunc tbox_overleft()
832
 */
833
Datum
834
Overleft_tbox_tbox(PG_FUNCTION_ARGS)
19,604✔
835
{
836
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,604✔
837
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,604✔
838
  PG_RETURN_BOOL(overleft_tbox_tbox(box1, box2));
19,604✔
839
}
840

841
PGDLLEXPORT Datum Right_tbox_tbox(PG_FUNCTION_ARGS);
842
PG_FUNCTION_INFO_V1(Right_tbox_tbox);
2✔
843
/**
844
 * @ingroup mobilitydb_box_pos
845
 * @brief Return true if the first temporal box is strictly to the right of the second one
846
 * @sqlfunc tbox_right()
847
 */
848
Datum
849
Right_tbox_tbox(PG_FUNCTION_ARGS)
19,604✔
850
{
851
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,604✔
852
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,604✔
853
  PG_RETURN_BOOL(right_tbox_tbox(box1, box2));
19,604✔
854
}
855

856
PGDLLEXPORT Datum Overright_tbox_tbox(PG_FUNCTION_ARGS);
857
PG_FUNCTION_INFO_V1(Overright_tbox_tbox);
2✔
858
/**
859
 * @ingroup mobilitydb_box_pos
860
 * @brief Return true if the first temporal box does not extend to the left of the second one
861
 * @sqlfunc tbox_overright()
862
 */
863
Datum
864
Overright_tbox_tbox(PG_FUNCTION_ARGS)
19,604✔
865
{
866
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,604✔
867
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,604✔
868
  PG_RETURN_BOOL(overright_tbox_tbox(box1, box2));
19,604✔
869
}
870

871
PGDLLEXPORT Datum Before_tbox_tbox(PG_FUNCTION_ARGS);
872
PG_FUNCTION_INFO_V1(Before_tbox_tbox);
2✔
873
/**
874
 * @ingroup mobilitydb_box_pos
875
 * @brief Return true if the first temporal box is strictly before the second one
876
 * @sqlfunc tbox_before()
877
 */
878
Datum
879
Before_tbox_tbox(PG_FUNCTION_ARGS)
19,604✔
880
{
881
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,604✔
882
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,604✔
883
  PG_RETURN_BOOL(before_tbox_tbox(box1, box2));
19,604✔
884
}
885

886
PGDLLEXPORT Datum Overbefore_tbox_tbox(PG_FUNCTION_ARGS);
887
PG_FUNCTION_INFO_V1(Overbefore_tbox_tbox);
2✔
888
/**
889
 * @ingroup mobilitydb_box_pos
890
 * @brief Return true if the first temporal box does not extend after the second one
891
 * @sqlfunc tbox_overbefore()
892
 */
893
Datum
894
Overbefore_tbox_tbox(PG_FUNCTION_ARGS)
19,604✔
895
{
896
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,604✔
897
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,604✔
898
  PG_RETURN_BOOL(overbefore_tbox_tbox(box1, box2));
19,604✔
899
}
900

901
PGDLLEXPORT Datum After_tbox_tbox(PG_FUNCTION_ARGS);
902
PG_FUNCTION_INFO_V1(After_tbox_tbox);
2✔
903
/**
904
 * @ingroup mobilitydb_box_pos
905
 * @brief Return true if the first temporal box is strictly after the second one
906
 * @sqlfunc tbox_after()
907
 */
908
Datum
909
After_tbox_tbox(PG_FUNCTION_ARGS)
19,604✔
910
{
911
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,604✔
912
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,604✔
913
  PG_RETURN_BOOL(after_tbox_tbox(box1, box2));
19,604✔
914
}
915

916
PGDLLEXPORT Datum Overafter_tbox_tbox(PG_FUNCTION_ARGS);
917
PG_FUNCTION_INFO_V1(Overafter_tbox_tbox);
2✔
918
/**
919
 * @ingroup mobilitydb_box_pos
920
 * @brief Return true if the first temporal box does not extend before the second one
921
 * @sqlfunc tbox_overafter()
922
 */
923
Datum
924
Overafter_tbox_tbox(PG_FUNCTION_ARGS)
19,604✔
925
{
926
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,604✔
927
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,604✔
928
  PG_RETURN_BOOL(overafter_tbox_tbox(box1, box2));
19,604✔
929
}
930

931
/*****************************************************************************
932
 * Set operators
933
 *****************************************************************************/
934

935
PGDLLEXPORT Datum Union_tbox_tbox(PG_FUNCTION_ARGS);
936
PG_FUNCTION_INFO_V1(Union_tbox_tbox);
2✔
937
/**
938
 * @ingroup mobilitydb_box_set
939
 * @brief Return the union of the temporal boxes
940
 * @sqlfunc union()
941
 * @sqlop @p +
942
 */
943
Datum
944
Union_tbox_tbox(PG_FUNCTION_ARGS)
211✔
945
{
946
  TBox *box1 = PG_GETARG_TBOX_P(0);
211✔
947
  TBox *box2 = PG_GETARG_TBOX_P(1);
211✔
948
  TBox *result = union_tbox_tbox(box1, box2, true);
211✔
949
  PG_RETURN_POINTER(result);
201✔
950
}
951

952
PGDLLEXPORT Datum Intersection_tbox_tbox(PG_FUNCTION_ARGS);
953
PG_FUNCTION_INFO_V1(Intersection_tbox_tbox);
2✔
954
/**
955
 * @ingroup mobilitydb_box_set
956
 * @brief Return the intersection of the temporal boxes
957
 * @sqlfunc intersection()
958
 * @sqlop @p *
959
 */
960
Datum
961
Intersection_tbox_tbox(PG_FUNCTION_ARGS)
19,613✔
962
{
963
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,613✔
964
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,613✔
965
  TBox *result = intersection_tbox_tbox(box1, box2);
19,613✔
966
  if (! result)
19,613✔
967
    PG_RETURN_NULL();
19,408✔
968
  PG_RETURN_POINTER(result);
205✔
969
}
970

971
/*****************************************************************************
972
 * Extent aggregation
973
 *****************************************************************************/
974

975
PGDLLEXPORT Datum Tbox_extent_transfn(PG_FUNCTION_ARGS);
976
PG_FUNCTION_INFO_V1(Tbox_extent_transfn);
5✔
977
/**
978
 * @brief Transition function for extent aggregation for boxes
979
 */
980
Datum
981
Tbox_extent_transfn(PG_FUNCTION_ARGS)
10,204✔
982
{
983
  TBox *box1 = PG_ARGISNULL(0) ? NULL : PG_GETARG_TBOX_P(0);
10,204✔
984
  TBox *box2 = PG_ARGISNULL(1) ? NULL : PG_GETARG_TBOX_P(1);
10,204✔
985

986
  /* Can't do anything with null inputs */
987
  if (! box1 && ! box2)
10,204✔
988
    PG_RETURN_NULL();
101✔
989
  TBox *result = palloc(sizeof(TBox));
10,103✔
990
  /* One of the boxes is null, return the other one */
991
  if (! box1)
10,103✔
992
  {
993
    memcpy(result, box2, sizeof(TBox));
994
    PG_RETURN_POINTER(result);
4✔
995
  }
996
  if (! box2)
10,099✔
997
  {
998
    memcpy(result, box1, sizeof(TBox));
999
    PG_RETURN_POINTER(result);
301✔
1000
  }
1001

1002
  /* Both boxes are not null */
1003
  memcpy(result, box1, sizeof(TBox));
1004
  tbox_expand(box2, result);
9,798✔
1005
  PG_RETURN_POINTER(result);
9,798✔
1006
}
1007

1008
PGDLLEXPORT Datum Tbox_extent_combinefn(PG_FUNCTION_ARGS);
1009
PG_FUNCTION_INFO_V1(Tbox_extent_combinefn);
4✔
1010
/**
1011
 * @brief Combine function for extent aggregation for temporal boxes
1012
 */
1013
Datum
1014
Tbox_extent_combinefn(PG_FUNCTION_ARGS)
31✔
1015
{
1016
  TBox *box1 = PG_ARGISNULL(0) ? NULL : PG_GETARG_TBOX_P(0);
31✔
1017
  TBox *box2 = PG_ARGISNULL(1) ? NULL : PG_GETARG_TBOX_P(1);
31✔
1018
  if (!box1 && !box2)
31✔
1019
    PG_RETURN_NULL();
×
1020
  if (box1 && !box2)
31✔
1021
    PG_RETURN_POINTER(box1);
20✔
1022
  if (!box1 && box2)
11✔
1023
    PG_RETURN_POINTER(box2);
11✔
1024
  /* Both boxes are not null */
1025
  ensure_same_dimensionality_tbox(box1, box2);
×
NEW
1026
  TBox *result = tbox_cp(box1);
×
1027
  tbox_expand(box2, result);
×
1028
  PG_RETURN_POINTER(result);
×
1029
}
1030

1031
/*****************************************************************************
1032
 * Comparison functions
1033
 *****************************************************************************/
1034

1035
PGDLLEXPORT Datum Tbox_cmp(PG_FUNCTION_ARGS);
1036
PG_FUNCTION_INFO_V1(Tbox_cmp);
6✔
1037
/**
1038
 * @ingroup mobilitydb_box_comp
1039
 * @brief Return -1, 0, or 1 depending on whether the first temporal box
1040
 * is less than, equal, or greater than the second one
1041
 *
1042
 * @note Function used for B-tree comparison
1043
 * @sqlfunc tbox_cmp()
1044
 */
1045
Datum
1046
Tbox_cmp(PG_FUNCTION_ARGS)
40,305✔
1047
{
1048
  TBox *box1 = PG_GETARG_TBOX_P(0);
40,305✔
1049
  TBox *box2 = PG_GETARG_TBOX_P(1);
40,305✔
1050
  PG_RETURN_INT32(tbox_cmp(box1, box2));
40,305✔
1051
}
1052

1053
PGDLLEXPORT Datum Tbox_lt(PG_FUNCTION_ARGS);
1054
PG_FUNCTION_INFO_V1(Tbox_lt);
2✔
1055
/**
1056
 * @ingroup mobilitydb_box_comp
1057
 * @brief Return true if the first temporal box is less than the second one
1058
 * @sqlfunc tbox_lt()
1059
 * @sqlop @p <
1060
 */
1061
Datum
1062
Tbox_lt(PG_FUNCTION_ARGS)
19,602✔
1063
{
1064
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,602✔
1065
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,602✔
1066
  PG_RETURN_BOOL(tbox_lt(box1, box2));
19,602✔
1067
}
1068

1069
PGDLLEXPORT Datum Tbox_le(PG_FUNCTION_ARGS);
1070
PG_FUNCTION_INFO_V1(Tbox_le);
2✔
1071
/**
1072
 * @ingroup mobilitydb_box_comp
1073
 * @brief Return true if the first temporal box is less than or equal to
1074
 * the second one
1075
 * @sqlfunc tbox_le()
1076
 * @sqlop @p <=
1077
 */
1078
Datum
1079
Tbox_le(PG_FUNCTION_ARGS)
19,602✔
1080
{
1081
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,602✔
1082
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,602✔
1083
  PG_RETURN_BOOL(tbox_le(box1, box2));
19,602✔
1084
}
1085

1086
PGDLLEXPORT Datum Tbox_ge(PG_FUNCTION_ARGS);
1087
PG_FUNCTION_INFO_V1(Tbox_ge);
2✔
1088
/**
1089
 * @ingroup mobilitydb_box_comp
1090
 * @brief Return true if the first temporal box is greater than or equal to
1091
 * the second one
1092
 * @sqlfunc tbox_ge()
1093
 * @sqlop @p >=
1094
 */
1095
Datum
1096
Tbox_ge(PG_FUNCTION_ARGS)
19,602✔
1097
{
1098
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,602✔
1099
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,602✔
1100
  PG_RETURN_BOOL(tbox_ge(box1, box2));
19,602✔
1101
}
1102

1103
PGDLLEXPORT Datum Tbox_gt(PG_FUNCTION_ARGS);
1104
PG_FUNCTION_INFO_V1(Tbox_gt);
2✔
1105
/**
1106
 * @ingroup mobilitydb_box_comp
1107
 * @brief Return true if the first temporal box is greater than the second one
1108
 * @sqlfunc tbox_gt()
1109
 * @sqlop @p >
1110
 */
1111
Datum
1112
Tbox_gt(PG_FUNCTION_ARGS)
19,602✔
1113
{
1114
  TBox *box1 = PG_GETARG_TBOX_P(0);
19,602✔
1115
  TBox *box2 = PG_GETARG_TBOX_P(1);
19,602✔
1116
  PG_RETURN_BOOL(tbox_gt(box1, box2));
19,602✔
1117
}
1118

1119
PGDLLEXPORT Datum Tbox_eq(PG_FUNCTION_ARGS);
1120
PG_FUNCTION_INFO_V1(Tbox_eq);
3✔
1121
/**
1122
 * @ingroup mobilitydb_box_comp
1123
 * @brief Return true if the temporal boxes are equal
1124
 * @sqlfunc tbox_eq()
1125
 * @sqlop @p =
1126
 */
1127
Datum
1128
Tbox_eq(PG_FUNCTION_ARGS)
22,111✔
1129
{
1130
  TBox *box1 = PG_GETARG_TBOX_P(0);
22,111✔
1131
  TBox *box2 = PG_GETARG_TBOX_P(1);
22,111✔
1132
  PG_RETURN_BOOL(tbox_eq(box1, box2));
22,111✔
1133
}
1134

1135
PGDLLEXPORT Datum Tbox_ne(PG_FUNCTION_ARGS);
1136
PG_FUNCTION_INFO_V1(Tbox_ne);
2✔
1137
/**
1138
 * @ingroup mobilitydb_box_comp
1139
 * @brief Return true if the temporal boxes are different
1140
 * @sqlfunc tbox_ne()
1141
 * @sqlop @p <>
1142
 */
1143
Datum
1144
Tbox_ne(PG_FUNCTION_ARGS)
20,196✔
1145
{
1146
  TBox *box1 = PG_GETARG_TBOX_P(0);
20,196✔
1147
  TBox *box2 = PG_GETARG_TBOX_P(1);
20,196✔
1148
  PG_RETURN_BOOL(tbox_ne(box1, box2));
20,196✔
1149
}
1150

1151
/*****************************************************************************/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc