Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/api/C6Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const C6Constants = {
ST_GEOMFROMWKB: 'ST_GeomFromWKB',
ST_INTERSECTS: 'ST_Intersects',
ST_LENGTH: 'ST_Length',
ST_MAKEENVELOPE: 'ST_MakeEnvelope',
ST_OVERLAPS: 'ST_Overlaps',
ST_POINT: 'ST_Point',
ST_SETSRID: 'ST_SetSRID',
Expand Down
6 changes: 6 additions & 0 deletions src/api/orm/queryHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ export const fieldEq = (leftCol: string, rightCol: string, leftAlias: string, ri
// ST_Distance_Sphere for aliased fields
export const distSphere = (fromCol: string, toCol: string, fromAlias: string, toAlias: string): any[] =>
[C6C.ST_DISTANCE_SPHERE, F(fromCol, fromAlias), F(toCol, toAlias)];

// Build a bounding-box expression
export const bbox = (minLng: number, minLat: number, maxLng: number, maxLat: number): any[] =>
[C6C.ST_SRID, [C6C.ST_MAKEENVELOPE,
[C6C.ST_POINT, minLng, minLat],
[C6C.ST_POINT, maxLng, maxLat]], 4326];
44 changes: 44 additions & 0 deletions test/queryHelpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import assert from 'assert';
import { bbox, C6C } from '../dist/index.esm.js';

// Verify basic bounding box construction
const expected = [
C6C.ST_SRID,
[
C6C.ST_MAKEENVELOPE,
[C6C.ST_POINT, 10, 20],
[C6C.ST_POINT, 30, 40],
],
4326,
];
const actual = bbox(10, 20, 30, 40);
assert.deepStrictEqual(actual, expected);
console.log('\u001B[32m✓\u001B[39m bbox basic structure test passed');

// Negative coordinate handling
const expectedNegative = [
C6C.ST_SRID,
[
C6C.ST_MAKEENVELOPE,
[C6C.ST_POINT, -10, -20],
[C6C.ST_POINT, -30, -40],
],
4326,
];
const actualNegative = bbox(-10, -20, -30, -40);
assert.deepStrictEqual(actualNegative, expectedNegative);
console.log('\u001B[32m✓\u001B[39m bbox negative coordinates test passed');

// Swapped min/max arguments
const expectedSwapped = [
C6C.ST_SRID,
[
C6C.ST_MAKEENVELOPE,
[C6C.ST_POINT, 30, 40],
[C6C.ST_POINT, 10, 20],
],
4326,
];
const actualSwapped = bbox(30, 40, 10, 20);
assert.deepStrictEqual(actualSwapped, expectedSwapped);
console.log('\u001B[32m✓\u001B[39m bbox swapped arguments test passed');
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './queryHelpers.test.js';
import assert from 'assert';

// basic sanity test to ensure test infrastructure runs
Expand Down