Skip to content
Permalink
Browse files

Cleaning up code

  • Loading branch information
Esteban Zimanyi
Esteban Zimanyi committed Feb 13, 2020
1 parent cd44052 commit 4b74b4d72bcef84e714e9dc66af41349a55a6ae8
Showing with 45 additions and 32 deletions.
  1. +1 −0 include/temporalinst.h
  2. +1 −1 include/temporalseq.h
  3. +3 −3 point/src/tpoint_spatialfuncs.c
  4. +3 −3 point/src/tpoint_tempspatialrels.c
  5. +12 −12 src/lifting.c
  6. +12 −0 src/temporalinst.c
  7. +13 −13 src/temporalseq.c
@@ -26,6 +26,7 @@ extern TemporalInst *temporalinst_copy(TemporalInst *inst);
extern Datum* temporalinst_value_ptr(TemporalInst *inst);
extern Datum temporalinst_value(TemporalInst *inst);
extern Datum temporalinst_value_copy(TemporalInst *inst);
extern void temporalinst_set(TemporalInst *inst, Datum value, TimestampTz t);

/* Input/output functions */

@@ -139,7 +139,7 @@ extern TemporalS *temporalseq_minus_min(TemporalSeq *seq);
extern TemporalS *temporalseq_at_max(TemporalSeq *seq);
extern TemporalS *temporalseq_minus_max(TemporalSeq *seq);
extern TemporalInst *temporalseq_at_timestamp1(TemporalInst *inst1,
TemporalInst *inst2, bool linear, TimestampTz t);
TemporalInst *inst2, TimestampTz t, bool linear);
extern TemporalInst *temporalseq_at_timestamp(TemporalSeq *seq, TimestampTz t);
extern bool temporalseq_value_at_timestamp(TemporalSeq *seq, TimestampTz t, Datum *result);
extern int temporalseq_minus_timestamp1(TemporalSeq **result, TemporalSeq *seq,
@@ -1708,7 +1708,7 @@ tpointseq_at_geometry1(TemporalInst *inst1, TemporalInst *inst2, bool linear,
if ((lower_inc || t > inst1->t) && (upper_inc || t < inst2->t))
{
/* Restriction at timestamp done to avoid floating point imprecision */
instants[0] = temporalseq_at_timestamp1(inst1, inst2, linear, t);
instants[0] = temporalseq_at_timestamp1(inst1, inst2, t, linear);
result[k++] = temporalseq_from_temporalinstarr(instants, 1,
true, true, linear, false);
pfree(instants[0]);
@@ -1729,8 +1729,8 @@ tpointseq_at_geometry1(TemporalInst *inst1, TemporalInst *inst2, bool linear,
TimestampTz lower1 = Min(t1, t2);
TimestampTz upper1 = Max(t1, t2);
/* Restriction at timestamp done to avoid floating point imprecision */
instants[0] = temporalseq_at_timestamp1(inst1, inst2, linear, lower1);
instants[1] = temporalseq_at_timestamp1(inst1, inst2, linear, upper1);
instants[0] = temporalseq_at_timestamp1(inst1, inst2, lower1, linear);
instants[1] = temporalseq_at_timestamp1(inst1, inst2, upper1, linear);
bool lower_inc1 = timestamp_cmp_internal(lower1, inst1->t) == 0 ?
lower_inc : true;
bool upper_inc1 = timestamp_cmp_internal(upper1, inst2->t) == 0 ?
@@ -748,7 +748,7 @@ tdwithin_tpointseq_geo1(TemporalSeq *seq, Datum geo, Datum dist, int *count)
pfree(instants[0]); pfree(instants[1]);
k++;
}
truevalue = !truevalue;
truevalue = ! truevalue;
}
pfree(ps); pfree(minus);
return result;
@@ -1111,10 +1111,10 @@ tdwithin_tpointseq_tpointseq2(TemporalSeq **result,
Datum sv2 = temporalinst_value(start2);
Datum ev2 = temporalinst_value(end2);
bool hasz = MOBDB_FLAGS_GET_Z(start1->flags);
TemporalInst *instants[2];
Datum datum_true = BoolGetDatum(true);
Datum datum_false = BoolGetDatum(false);

TemporalInst *instants[2];

/* Both segments are constant */
if (datum_point_eq(sv1, ev1) && datum_point_eq(sv2, ev2))
{
@@ -2633,15 +2633,15 @@ sync_tfunc2_temporalseq_temporalseq_cross2(TemporalSeq **result, TemporalSeq *se
else if (cmp < 0)
{
i++;
end2 = temporalseq_at_timestamp1(start2, end2,
MOBDB_FLAGS_GET_LINEAR(seq2->flags), end1->t);
end2 = temporalseq_at_timestamp1(start2, end2, end1->t,
MOBDB_FLAGS_GET_LINEAR(seq2->flags));
tofree[l++] = end2;
}
else
{
j++;
end1 = temporalseq_at_timestamp1(start1, end1,
MOBDB_FLAGS_GET_LINEAR(seq1->flags), end2->t);
end1 = temporalseq_at_timestamp1(start1, end1, end2->t,
MOBDB_FLAGS_GET_LINEAR(seq1->flags));
tofree[l++] = end1;
}
bool upper_inc = (timestamp_cmp_internal(end1->t, inter->upper) == 0) ?
@@ -3030,15 +3030,15 @@ sync_tfunc3_temporalseq_temporalseq_cross2(TemporalSeq **result,
else if (cmp < 0)
{
i++;
end2 = temporalseq_at_timestamp1(start2, end2,
MOBDB_FLAGS_GET_LINEAR(seq2->flags), end1->t);
end2 = temporalseq_at_timestamp1(start2, end2, end1->t,
MOBDB_FLAGS_GET_LINEAR(seq2->flags));
tofree[l++] = end2;
}
else
{
j++;
end1 = temporalseq_at_timestamp1(start1, end1,
MOBDB_FLAGS_GET_LINEAR(seq1->flags), end2->t);
end1 = temporalseq_at_timestamp1(start1, end1, end2->t,
MOBDB_FLAGS_GET_LINEAR(seq1->flags));
tofree[l++] = end1;
}
bool upper_inc = (timestamp_cmp_internal(end1->t, inter->upper) == 0) ?
@@ -3444,15 +3444,15 @@ sync_tfunc4_temporalseq_temporalseq_cross2(TemporalSeq **result,
else if (cmp < 0)
{
i++;
end2 = temporalseq_at_timestamp1(start2, end2,
MOBDB_FLAGS_GET_LINEAR(seq2->flags), end1->t);
end2 = temporalseq_at_timestamp1(start2, end2, end1->t,
MOBDB_FLAGS_GET_LINEAR(seq2->flags));
tofree[l++] = end2;
}
else
{
j++;
end1 = temporalseq_at_timestamp1(start1, end1,
MOBDB_FLAGS_GET_LINEAR(seq1->flags), end2->t);
end1 = temporalseq_at_timestamp1(start1, end1, end2->t,
MOBDB_FLAGS_GET_LINEAR(seq1->flags));
tofree[l++] = end1;
}
bool upper_inc = (timestamp_cmp_internal(end1->t, inter->upper) == 0) ?
@@ -171,6 +171,18 @@ temporalinst_copy(TemporalInst *inst)
return result;
}

/* Set the value and the timestamp of an existing temporal instant.
* This function only works for for base types passed by value.
* This should be ensured by the calling function! */
void
temporalinst_set(TemporalInst *inst, Datum value, TimestampTz t)
{
inst->t = t;
Datum *value_ptr = temporalinst_value_ptr(inst);
*value_ptr = value;

}

/*****************************************************************************
* Intput/output functions
*****************************************************************************/
@@ -1076,9 +1076,9 @@ synchronize_temporalseq_temporalseq(TemporalSeq *seq1, TemporalSeq *seq2,
inst1, linear1, instants2[k - 1], inst2, linear2, &crosstime))
{
instants1[k] = tofree[l++] = temporalseq_at_timestamp1(
instants1[k - 1], inst1, linear1, crosstime);
instants1[k - 1], inst1, crosstime, linear1);
instants2[k] = tofree[l++] = temporalseq_at_timestamp1(
instants2[k - 1], inst2, linear2, crosstime);
instants2[k - 1], inst2, crosstime, linear2);
k++;
}
}
@@ -3230,8 +3230,8 @@ temporalseq_value_at_timestamp(TemporalSeq *seq, TimestampTz t, Datum *result)
* (both inclusive).
*/
TemporalInst *
temporalseq_at_timestamp1(TemporalInst *inst1, TemporalInst *inst2, bool linear,
TimestampTz t)
temporalseq_at_timestamp1(TemporalInst *inst1, TemporalInst *inst2,
TimestampTz t, bool linear)
{
Datum value = temporalseq_value_at_timestamp1(inst1, inst2, linear, t);
TemporalInst *result = temporalinst_make(value, t, inst1->valuetypid);
@@ -3257,7 +3257,7 @@ temporalseq_at_timestamp(TemporalSeq *seq, TimestampTz t)
int n = temporalseq_find_timestamp(seq, t);
TemporalInst *inst1 = temporalseq_inst_n(seq, n);
TemporalInst *inst2 = temporalseq_inst_n(seq, n + 1);
return temporalseq_at_timestamp1(inst1, inst2, MOBDB_FLAGS_GET_LINEAR(seq->flags), t);
return temporalseq_at_timestamp1(inst1, inst2, t, MOBDB_FLAGS_GET_LINEAR(seq->flags));
}

/*
@@ -3313,7 +3313,7 @@ temporalseq_minus_timestamp1(TemporalSeq **result, TemporalSeq *seq,
{
instants[n] = inst1;
instants[n + 1] = linear ?
temporalseq_at_timestamp1(inst1, inst2, true, t) :
temporalseq_at_timestamp1(inst1, inst2, t, true) :
temporalinst_make(temporalinst_value(inst1), t,
inst1->valuetypid);
result[k++] = temporalseq_from_temporalinstarr(instants, n + 2,
@@ -3326,8 +3326,8 @@ temporalseq_minus_timestamp1(TemporalSeq **result, TemporalSeq *seq,
inst2 = temporalseq_inst_n(seq, n + 1);
if (timestamp_cmp_internal(t, inst2->t) < 0)
{
instants[0] = temporalseq_at_timestamp1(inst1, inst2,
MOBDB_FLAGS_GET_LINEAR(seq->flags), t);
instants[0] = temporalseq_at_timestamp1(inst1, inst2, t,
MOBDB_FLAGS_GET_LINEAR(seq->flags));
for (int i = 1; i < seq->count - n; i++)
instants[i] = temporalseq_inst_n(seq, i + n);
result[k++] = temporalseq_from_temporalinstarr(instants, seq->count - n,
@@ -3499,10 +3499,10 @@ temporalseq_at_period(TemporalSeq *seq, Period *p)
/* Compute the value at the beginning of the intersecting period */
TemporalInst *inst1 = temporalseq_inst_n(seq, n);
TemporalInst *inst2 = temporalseq_inst_n(seq, n + 1);
instants[0] = temporalseq_at_timestamp1(inst1, inst2,
MOBDB_FLAGS_GET_LINEAR(seq->flags), inter->lower);
instants[0] = temporalseq_at_timestamp1(inst1, inst2, inter->lower,
MOBDB_FLAGS_GET_LINEAR(seq->flags));
int k = 1;
for (int i = n+2; i < seq->count; i++)
for (int i = n + 2; i < seq->count; i++)
{
/* If the end of the intersecting period is between inst1 and inst2 */
if (timestamp_cmp_internal(inst1->t, inter->upper) <= 0 &&
@@ -3519,8 +3519,8 @@ temporalseq_at_period(TemporalSeq *seq, Period *p)
/* The last two values of sequences with stepwise interpolation and
exclusive upper bound must be equal */
if (MOBDB_FLAGS_GET_LINEAR(seq->flags) || inter->upper_inc)
instants[k++] = temporalseq_at_timestamp1(inst1, inst2,
MOBDB_FLAGS_GET_LINEAR(seq->flags), inter->upper);
instants[k++] = temporalseq_at_timestamp1(inst1, inst2, inter->upper,
MOBDB_FLAGS_GET_LINEAR(seq->flags));
else
{
Datum value = temporalinst_value(instants[k - 1]);

0 comments on commit 4b74b4d

Please sign in to comment.
You can’t perform that action at this time.