97
97
#include < date/iso_week.h>
98
98
#include < date/tz.h>
99
99
#include < s2/s2loop.h>
100
+ #include < s2/s2polygon.h>
100
101
101
102
#include < unicode/schriter.h>
102
103
#include < unicode/stsearch.h>
@@ -1200,7 +1201,8 @@ AqlValue geoContainsIntersect(ExpressionContext* expressionContext,
1200
1201
1201
1202
AqlValueMaterializer mat1 (vopts);
1202
1203
geo::ShapeContainer outer, inner;
1203
- Result res = geo::geojson::parseRegion (mat1.slice (p1, true ), outer, false );
1204
+ auto res = geo::json::parseRegion (mat1.slice (p1, true ), outer,
1205
+ /* legacy=*/ false );
1204
1206
if (res.fail ()) {
1205
1207
registerWarning (expressionContext, func, res);
1206
1208
return AqlValue (AqlValueHintNull ());
@@ -1215,13 +1217,12 @@ AqlValue geoContainsIntersect(ExpressionContext* expressionContext,
1215
1217
}
1216
1218
1217
1219
AqlValueMaterializer mat2 (vopts);
1218
- if (p2.isArray () && p2.length () >= 2 ) {
1219
- res = inner.parseCoordinates (mat2.slice (p2, true ), /* geoJson*/ true );
1220
- } else if (p2.isObject ()) {
1221
- res = geo::geojson::parseRegion (mat2.slice (p2, true ), inner, false );
1220
+ if (p2.isArray ()) {
1221
+ res = geo::json::parseCoordinates<true >(mat2.slice (p2, true ), inner,
1222
+ /* geoJson=*/ true );
1222
1223
} else {
1223
- res. reset (TRI_ERROR_BAD_PARAMETER ,
1224
- " Second arg requires coordinate pair or GeoJSON " );
1224
+ res = geo::json::parseRegion (mat2. slice (p2, true ), inner ,
1225
+ /* legacy= */ false );
1225
1226
}
1226
1227
if (res.fail ()) {
1227
1228
registerWarning (expressionContext, func, res);
@@ -1230,7 +1231,7 @@ AqlValue geoContainsIntersect(ExpressionContext* expressionContext,
1230
1231
1231
1232
bool result;
1232
1233
try {
1233
- result = contains ? outer.contains (& inner) : outer.intersects (& inner);
1234
+ result = contains ? outer.contains (inner) : outer.intersects (inner);
1234
1235
return AqlValue (AqlValueHintBool (result));
1235
1236
} catch (basics::Exception const & ex) {
1236
1237
res.reset (ex.code (), ex.what ());
@@ -1339,13 +1340,12 @@ Result parseShape(ExpressionContext* exprCtx, AqlValue const& value,
1339
1340
auto * vopts = &exprCtx->trx ().vpackOptions ();
1340
1341
AqlValueMaterializer mat (vopts);
1341
1342
1342
- if (value.isArray () && value.length () >= 2 ) {
1343
- return shape.parseCoordinates (mat.slice (value, true ), /* geoJson*/ true );
1344
- } else if (value.isObject ()) {
1345
- return geo::geojson::parseRegion (mat.slice (value, true ), shape, false );
1346
- } else {
1347
- return {TRI_ERROR_BAD_PARAMETER, " Requires coordinate pair or GeoJSON" };
1343
+ if (value.isArray ()) {
1344
+ return geo::json::parseCoordinates<true >(mat.slice (value, true ), shape,
1345
+ /* geoJson=*/ true );
1348
1346
}
1347
+ return geo::json::parseRegion (mat.slice (value, true ), shape,
1348
+ /* legacy=*/ false );
1349
1349
}
1350
1350
1351
1351
} // namespace
@@ -6016,12 +6016,12 @@ AqlValue functions::GeoDistance(ExpressionContext* exprCtx, AstNode const&,
6016
6016
return AqlValue (AqlValueHintNull ());
6017
6017
}
6018
6018
6019
- if (parameters.size () > 2 && parameters[ 2 ]. isString () ) {
6020
- VPackValueLength len;
6021
- const char * ptr = parameters[ 2 ]. slice (). getStringUnchecked (len );
6022
- geo::Ellipsoid const & e = geo::utils::ellipsoidFromString (ptr, len);
6023
- return :: numberValue (shape1. distanceFromCentroid (shape2. centroid (), e),
6024
- true );
6019
+ if (parameters.size () > 2 ) {
6020
+ if ( auto slice = parameters[ 2 ]. slice (); slice. isString ()) {
6021
+ auto const & e = geo::utils::ellipsoidFromString (slice. stringView () );
6022
+ return :: numberValue (shape1. distanceFromCentroid (shape2. centroid (), e),
6023
+ true );
6024
+ }
6025
6025
}
6026
6026
return ::numberValue (shape1.distanceFromCentroid (shape2.centroid ()), true );
6027
6027
}
@@ -6107,10 +6107,8 @@ AqlValue functions::GeoInRange(ExpressionContext* ctx, AstNode const& node,
6107
6107
6108
6108
if (argc > 6 ) {
6109
6109
auto const & value = extractFunctionParameterValue (args, 6 );
6110
- if (value.isString ()) {
6111
- VPackValueLength len;
6112
- char const * ptr = value.slice ().getStringUnchecked (len);
6113
- ellipsoid = &geo::utils::ellipsoidFromString (ptr, len);
6110
+ if (auto slice = value.slice (); slice.isString ()) {
6111
+ ellipsoid = &geo::utils::ellipsoidFromString (slice.stringView ());
6114
6112
}
6115
6113
}
6116
6114
}
@@ -6163,8 +6161,10 @@ AqlValue functions::GeoEquals(ExpressionContext* expressionContext,
6163
6161
AqlValueMaterializer mat2 (vopts);
6164
6162
6165
6163
geo::ShapeContainer first, second;
6166
- Result res1 = geo::geojson::parseRegion (mat1.slice (p1, true ), first, false );
6167
- Result res2 = geo::geojson::parseRegion (mat2.slice (p2, true ), second, false );
6164
+ auto res1 = geo::json::parseRegion (mat1.slice (p1, true ), first,
6165
+ /* legacy=*/ false );
6166
+ auto res2 = geo::json::parseRegion (mat2.slice (p2, true ), second,
6167
+ /* legacy=*/ false );
6168
6168
6169
6169
if (res1.fail ()) {
6170
6170
registerWarning (expressionContext, " GEO_EQUALS" , res1);
@@ -6175,7 +6175,7 @@ AqlValue functions::GeoEquals(ExpressionContext* expressionContext,
6175
6175
return AqlValue (AqlValueHintNull ());
6176
6176
}
6177
6177
6178
- bool result = first.equals (& second);
6178
+ bool result = first.equals (second);
6179
6179
return AqlValue (AqlValueHintBool (result));
6180
6180
}
6181
6181
@@ -6191,18 +6191,17 @@ AqlValue functions::GeoArea(ExpressionContext* expressionContext,
6191
6191
AqlValueMaterializer mat (vopts);
6192
6192
6193
6193
geo::ShapeContainer shape;
6194
- Result res = geo::geojson::parseRegion (mat.slice (p1, true ), shape, false );
6194
+ auto res = geo::json::parseRegion (mat.slice (p1, true ), shape,
6195
+ /* legacy=*/ false );
6195
6196
6196
6197
if (res.fail ()) {
6197
6198
registerWarning (expressionContext, " GEO_AREA" , res);
6198
6199
return AqlValue (AqlValueHintNull ());
6199
6200
}
6200
6201
6201
6202
auto detEllipsoid = [](AqlValue const & p) {
6202
- if (p.isString ()) {
6203
- VPackValueLength len;
6204
- const char * ptr = p.slice ().getStringUnchecked (len);
6205
- return geo::utils::ellipsoidFromString (ptr, len);
6203
+ if (auto slice = p.slice (); slice.isString ()) {
6204
+ return geo::utils::ellipsoidFromString (slice.stringView ());
6206
6205
}
6207
6206
return geo::SPHERE;
6208
6207
};
@@ -6259,13 +6258,13 @@ AqlValue functions::IsInPolygon(ExpressionContext* expressionContext,
6259
6258
6260
6259
S2Loop loop;
6261
6260
loop.set_s2debug_override (S2Debug::DISABLE);
6262
- Result res = geo::geojson ::parseLoop (coords.slice (), geoJson, loop );
6261
+ auto res = geo::json ::parseLoop (coords.slice (), loop, geoJson );
6263
6262
if (res.fail () || !loop.IsValid ()) {
6264
6263
registerWarning (expressionContext, " IS_IN_POLYGON" , res);
6265
6264
return AqlValue (AqlValueHintNull ());
6266
6265
}
6267
6266
6268
- S2LatLng latLng = S2LatLng::FromDegrees (latitude, longitude);
6267
+ S2LatLng latLng = S2LatLng::FromDegrees (latitude, longitude). Normalized () ;
6269
6268
return AqlValue (AqlValueHintBool (loop.Contains (latLng.ToPoint ())));
6270
6269
}
6271
6270
@@ -6421,8 +6420,8 @@ AqlValue functions::GeoPolygon(ExpressionContext* expressionContext,
6421
6420
builder->close (); // object
6422
6421
6423
6422
// Now actually parse the result with S2:
6424
- geo::ShapeContainer container ;
6425
- res = geo::geojson ::parsePolygon (builder->slice (), container, false );
6423
+ S2Polygon polygon ;
6424
+ res = geo::json ::parsePolygon (builder->slice (), polygon );
6426
6425
if (res.fail ()) {
6427
6426
registerWarning (expressionContext, " GEO_POLYGON" , res);
6428
6427
return AqlValue (AqlValueHintNull ());
@@ -6504,9 +6503,8 @@ AqlValue functions::GeoMultiPolygon(ExpressionContext* expressionContext,
6504
6503
builder->close ();
6505
6504
6506
6505
// Now actually parse the result with S2:
6507
- geo::ShapeContainer container;
6508
- Result res =
6509
- geo::geojson::parseMultiPolygon (builder->slice (), container, false );
6506
+ S2Polygon polygon;
6507
+ auto res = geo::json::parseMultiPolygon (builder->slice (), polygon);
6510
6508
if (res.fail ()) {
6511
6509
registerWarning (expressionContext, " GEO_MULTIPOLYGON" , res);
6512
6510
return AqlValue (AqlValueHintNull ());
@@ -7374,7 +7372,7 @@ std::optional<T> bitOperationValue(VPackSlice input) {
7374
7372
return {};
7375
7373
}
7376
7374
7377
- AqlValue handleBitOperation (
7375
+ static AqlValue handleBitOperation (
7378
7376
ExpressionContext* expressionContext, AstNode const & node,
7379
7377
VPackFunctionParametersView parameters,
7380
7378
std::function<uint64_t (uint64_t , uint64_t )> const & cb) {
0 commit comments