34
34
// If the bounds are bigger than the box itself, just clip at the borders
35
35
assert.eq( numItems, t.find(
36
{ loc : { $within : { $box : [
37
[ overallMin - 2 * epsilon, overallMin - 2 * epsilon ],
38
[ overallMax + 2 * epsilon, overallMax + 2 * epsilon ] ] } } } ).count() );
36
{ loc : { $within : { $box : [
37
[ overallMin - 2 * epsilon, overallMin - 2 * epsilon ],
38
[ overallMax + 2 * epsilon, overallMax + 2 * epsilon ] ] } } } ).count() );
40
40
// Check this works also for bounds where only a single dimension is off-bounds
41
41
assert.eq( numItems - 5, t.find(
42
{ loc : { $within : { $box : [
43
[ overallMin - 2 * epsilon, overallMin - 0.5 * epsilon ],
44
[ overallMax - epsilon, overallMax - epsilon ] ] } } } ).count() );
46
// Make sure we can get at least close to the bounds of the index
47
assert.eq( numItems, t.find(
48
{ loc : { $within : { $box : [
49
[ overallMin - epsilon / 2, overallMin - epsilon / 2 ],
50
[ overallMax + epsilon / 2, overallMax + epsilon / 2 ] ] } } } ).count() );
52
// Make sure we can get at least close to the bounds of the index
53
assert.eq( numItems, t.find(
54
{ loc : { $within : { $box : [
55
[ overallMax + epsilon / 2, overallMax + epsilon / 2 ],
56
[ overallMin - epsilon / 2, overallMin - epsilon / 2 ] ] } } } ).count() );
42
{ loc : { $within : { $box : [
43
[ overallMin - 2 * epsilon, overallMin - 0.5 * epsilon ],
44
[ overallMax - epsilon, overallMax - epsilon ] ] } } } ).count() );
46
// Make sure we can get at least close to the bounds of the index
47
assert.eq( numItems, t.find(
48
{ loc : { $within : { $box : [
49
[ overallMin - epsilon / 2, overallMin - epsilon / 2 ],
50
[ overallMax + epsilon / 2, overallMax + epsilon / 2 ] ] } } } ).count() );
52
// Make sure we can get at least close to the bounds of the index
53
assert.eq( numItems, t.find(
54
{ loc : { $within : { $box : [
55
[ overallMax + epsilon / 2, overallMax + epsilon / 2 ],
56
[ overallMin - epsilon / 2, overallMin - epsilon / 2 ] ] } } } ).count() );
58
58
// Check that swapping min/max has good behavior
59
59
assert.eq( numItems, t.find(
60
{ loc : { $within : { $box : [
61
[ overallMax + epsilon / 2, overallMax + epsilon / 2 ],
62
[ overallMin - epsilon / 2, overallMin - epsilon / 2 ] ] } } } ).count() );
60
{ loc : { $within : { $box : [
61
[ overallMax + epsilon / 2, overallMax + epsilon / 2 ],
62
[ overallMin - epsilon / 2, overallMin - epsilon / 2 ] ] } } } ).count() );
64
64
assert.eq( numItems, t.find(
65
{ loc : { $within : { $box : [
66
[ overallMax + epsilon / 2, overallMin - epsilon / 2 ],
67
[ overallMin - epsilon / 2, overallMax + epsilon / 2 ] ] } } } ).count() );
65
{ loc : { $within : { $box : [
66
[ overallMax + epsilon / 2, overallMin - epsilon / 2 ],
67
[ overallMin - epsilon / 2, overallMax + epsilon / 2 ] ] } } } ).count() );
96
96
// Make sure we get correct corner point when center is on bounds
97
97
// NOTE: Only valid points on MIN bounds
99
.findOne( { loc : { $within : { $center : [ onBoundsNeg, Math.sqrt( 2 * epsilon * epsilon ) + ( step / 2 ) ] } } } );
99
.findOne( { loc : { $within : { $center : [ onBoundsNeg, Math.sqrt( 2 * epsilon * epsilon ) + ( step / 2 ) ] } } } );
100
100
assert.eq( cornerPt.loc.y, overallMin )
102
102
// Make sure we can't get corner point when center is over bounds
104
t.findOne( { loc : { $within : { $center : [ offBounds, Math.sqrt( 8 * epsilon * epsilon ) + ( step / 2 ) ] } } } );
104
t.findOne( { loc : { $within : { $center : [ offBounds, Math.sqrt( 8 * epsilon * epsilon ) + ( step / 2 ) ] } } } );
109
109
// Make sure we can't get corner point when center is on max bounds
111
t.findOne( { loc : { $within : { $center : [ onBounds, Math.sqrt( 8 * epsilon * epsilon ) + ( step / 2 ) ] } } } );
111
t.findOne( { loc : { $within : { $center : [ onBounds, Math.sqrt( 8 * epsilon * epsilon ) + ( step / 2 ) ] } } } );