Skip to content

Commit 885cbab

Browse files
authored
Merge pull request #319 from ml054/v5.2
RDBC-594 distErrorPercent is overridden to default when is set as 0
2 parents 2c2995a + d8328cf commit 885cbab

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

src/Documents/Queries/Spatial/SpatialCriteriaFactory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class SpatialCriteriaFactory {
2424
relation: SpatialRelation,
2525
units?: SpatialUnits,
2626
distErrorPercent?: number): SpatialCriteria {
27-
if (!distErrorPercent) {
27+
if (TypeUtil.isNullOrUndefined(distErrorPercent)) {
2828
distErrorPercent = CONSTANTS.Documents.Indexing.Spatial.DEFAULT_DISTANCE_ERROR_PCT;
2929
}
3030

@@ -40,7 +40,7 @@ export class SpatialCriteriaFactory {
4040
units = null;
4141
}
4242

43-
distErrorPercent = distErrorPercent || CONSTANTS.Documents.Indexing.Spatial.DEFAULT_DISTANCE_ERROR_PCT;
43+
distErrorPercent = distErrorPercent ?? CONSTANTS.Documents.Indexing.Spatial.DEFAULT_DISTANCE_ERROR_PCT;
4444
return { units, distErrorPercent };
4545
}
4646

@@ -118,7 +118,7 @@ export class SpatialCriteriaFactory {
118118
longitude: number,
119119
radiusUnits: SpatialUnits = null,
120120
distErrorPercent?: number): SpatialCriteria {
121-
distErrorPercent = distErrorPercent || CONSTANTS.Documents.Indexing.Spatial.DEFAULT_DISTANCE_ERROR_PCT;
121+
distErrorPercent = distErrorPercent ?? CONSTANTS.Documents.Indexing.Spatial.DEFAULT_DISTANCE_ERROR_PCT;
122122
return new CircleCriteria(radius, latitude, longitude, radiusUnits, "Within", distErrorPercent);
123123
}
124124
}

test/Issues/RDBC_594.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { IDocumentStore, PointField } from "../../src";
2+
import { disposeTestDocumentStore, testContext } from "../Utils/TestUtil";
3+
import { User } from "../Assets/Entities";
4+
import { assertThat } from "../Utils/AssertExtensions";
5+
6+
7+
describe("RDBC_594", function () {
8+
let store: IDocumentStore;
9+
10+
beforeEach(async function () {
11+
store = await testContext.getDocumentStore();
12+
});
13+
14+
afterEach(async () =>
15+
await disposeTestDocumentStore(store));
16+
17+
describe("can use zero as distError", function () {
18+
it("relatedToShape", () => {
19+
const session = store.openSession();
20+
21+
const q1 = session.query(User)
22+
.spatial("WKT",
23+
f => f.relatesToShape("LINESTRING (1 0, 1 1, 1 2)", "Intersects", "Kilometers", 0))
24+
.toString();
25+
26+
assertThat(q1)
27+
.contains("spatial.intersects(WKT, spatial.wkt($p0, 'Kilometers'), 0)");
28+
});
29+
30+
it("intersects", () => {
31+
const session = store.openSession();
32+
33+
const q1 = session.query(User)
34+
.spatial("WKT",
35+
f => f.intersects("LINESTRING (1 0, 1 1, 1 2)", 0))
36+
.toString();
37+
38+
assertThat(q1)
39+
.contains("spatial.intersects(WKT, spatial.wkt($p0), 0)");
40+
});
41+
42+
it("contains", () => {
43+
const session = store.openSession();
44+
45+
const q1 = session.query(User)
46+
.spatial("WKT",
47+
f => f.contains("LINESTRING (1 0, 1 1, 1 2)", 0))
48+
.toString();
49+
50+
assertThat(q1)
51+
.contains("spatial.contains(WKT, spatial.wkt($p0), 0)");
52+
});
53+
54+
it("withinRadius", () => {
55+
const session = store.openSession();
56+
57+
const q1 = session.query(User)
58+
.spatial(new PointField("latitude2", "longitude2"), f => f.withinRadius(10, 10, 20, "Kilometers", 0))
59+
.toString();
60+
61+
assertThat(q1)
62+
.contains("spatial.within(spatial.point(latitude2, longitude2), spatial.circle($p0, $p1, $p2, 'Kilometers'), 0)");
63+
})
64+
})
65+
});

0 commit comments

Comments
 (0)