1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
use diesel::expression::AsExpression;
use diesel::sql_types::SqlType;
use diesel::Expression;

diesel::infix_operator!(BBIntersects2D, " && ");
diesel::infix_operator!(BBOverlapsOrLeft, " &< ");
diesel::infix_operator!(BBOverlapsOrBelow, " &<| ");
diesel::infix_operator!(BBOverlapsOrRight, " &> ");
diesel::infix_operator!(BBStrictlyLeft, " << ");
diesel::infix_operator!(BBStrictlyBelow, " <<| ");
diesel::infix_operator!(GSame, " = ");
diesel::infix_operator!(BBStrictlyRight, " >> ");
diesel::infix_operator!(BBContainedBy, " @ ");
diesel::infix_operator!(BBOverlapsOrAbove, " |&> ");
diesel::infix_operator!(BBStrictlyAbove, " |>> ");
diesel::infix_operator!(BBContains, " ~ ");
diesel::infix_operator!(BBSame, " ~= ");

diesel::infix_operator!(Distance2d, " <-> ", diesel::sql_types::Double);
diesel::infix_operator!(Distance3dTrajectories, " <-> ", diesel::sql_types::Double);
diesel::infix_operator!(Distance2BBs, " <#> ", diesel::sql_types::Double);
diesel::infix_operator!(DistanceNdCentroidsBBs, " <<->> ", diesel::sql_types::Double);
diesel::infix_operator!(DistanceNdBBs, " <<#>> ", diesel::sql_types::Double);

/// The @ operator returns TRUE if the bounding box of geometry A is completely contained by the bounding box of geometry B.
pub fn contained_by<T, U>(left: T, right: U) -> BBContainedBy<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBContainedBy::new(left, right.as_expression())
}

/// The ~ operator returns TRUE if the bounding box of geometry A completely contains the bounding box of geometry B.
pub fn contains<T, U>(left: T, right: U) -> BBContains<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBContains::new(left, right.as_expression())
}

/// The && operator returns TRUE if the 2D bounding box of geometry A intersects the 2D bounding box of geometry B.
pub fn intersects_2d<T, U>(left: T, right: U) -> BBIntersects2D<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBIntersects2D::new(left, right.as_expression())
}

/// The &< operator returns TRUE if the bounding box of geometry A overlaps or is to the left of the bounding box of geometry B, or more accurately, overlaps or is NOT to the right of the bounding box of geometry B.
pub fn overlaps_or_left<T, U>(left: T, right: U) -> BBOverlapsOrLeft<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBOverlapsOrLeft::new(left, right.as_expression())
}

/// The &<| operator returns TRUE if the bounding box of geometry A overlaps or is below of the bounding box of geometry B, or more accurately, overlaps or is NOT above the bounding box of geometry B.
pub fn overlaps_or_below<T, U>(left: T, right: U) -> BBOverlapsOrBelow<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBOverlapsOrBelow::new(left, right.as_expression())
}

/// The &> operator returns TRUE if the bounding box of geometry A overlaps or is to the right of the bounding box of geometry B, or more accurately, overlaps or is NOT to the left of the bounding box of geometry B.
pub fn overlaps_or_right<T, U>(left: T, right: U) -> BBOverlapsOrRight<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBOverlapsOrRight::new(left, right.as_expression())
}

/// The |&> operator returns TRUE if the bounding box of geometry A overlaps or is above the bounding box of geometry B, or more accurately, overlaps or is NOT below the bounding box of geometry B.
pub fn overlaps_or_above<T, U>(left: T, right: U) -> BBOverlapsOrAbove<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBOverlapsOrAbove::new(left, right.as_expression())
}

/// The << operator returns TRUE if the bounding box of geometry A is strictly to the left of the bounding box of geometry B.
pub fn strictly_left<T, U>(left: T, right: U) -> BBStrictlyLeft<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBStrictlyLeft::new(left, right.as_expression())
}

/// The <<| operator returns TRUE if the bounding box of geometry A is strictly below the bounding box of geometry B.
pub fn strictly_below<T, U>(left: T, right: U) -> BBStrictlyBelow<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBStrictlyBelow::new(left, right.as_expression())
}

/// The >> operator returns TRUE if the bounding box of geometry A is strictly to the right of the bounding box of geometry B.
pub fn strictly_right<T, U>(left: T, right: U) -> BBStrictlyRight<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBStrictlyRight::new(left, right.as_expression())
}

/// The |>> operator returns TRUE if the bounding box of geometry A is strictly above the bounding box of geometry B.
pub fn strictly_above<T, U>(left: T, right: U) -> BBStrictlyAbove<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBStrictlyAbove::new(left, right.as_expression())
}

/// The = operator returns TRUE if the coordinates and coordinate order geometry/geography A are the same as the coordinates and coordinate order of geometry/geography B.
pub fn g_same<T, U>(left: T, right: U) -> GSame<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    GSame::new(left, right.as_expression())
}

/// The ~= operator returns TRUE if the bounding box of geometry/geography A is the same as the bounding box of geometry/geography B.
pub fn bb_same<T, U>(left: T, right: U) -> BBSame<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    BBSame::new(left, right.as_expression())
}

/// The <-> operator returns the 2D distance between A and B.
pub fn distance_2d<T, U>(left: T, right: U) -> Distance2d<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    Distance2d::new(left, right.as_expression())
}

/// The |=| operator returns the 3D distance between two trajectories.
pub fn distance_3d_trajectories<T, U>(left: T, right: U) -> Distance3dTrajectories<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    Distance3dTrajectories::new(left, right.as_expression())
}

/// The <#> operator returns the 2D distance between A and B bounding boxes.
pub fn distance_2d_bbs<T, U>(left: T, right: U) -> Distance2BBs<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    Distance2BBs::new(left, right.as_expression())
}

/// The <<->> operator returns the n-D distance between the centroids of A and B bounding boxes.
pub fn distance_nd_centroids_bbs<T, U>(
    left: T,
    right: U,
) -> DistanceNdCentroidsBBs<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    DistanceNdCentroidsBBs::new(left, right.as_expression())
}

/// The <<#>> operator returns the n-D distance between A and B bounding boxes.
pub fn distance_nd_bbs<T, U>(left: T, right: U) -> DistanceNdBBs<T, U::Expression>
where
    T: Expression,
    <T as diesel::Expression>::SqlType: SqlType,
    U: AsExpression<T::SqlType>,
{
    DistanceNdBBs::new(left, right.as_expression())
}