|
232 | 232 | expect($testPlacesWithinPolygon[0]->point)->toEqual($pointWithinPolygon);
|
233 | 233 | });
|
234 | 234 |
|
| 235 | +it('filters by not within', function (): void { |
| 236 | + $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}', 4326); |
| 237 | + $pointWithinPolygon = new Point(0, 0, 4326); |
| 238 | + $pointOutsidePolygon = new Point(50, 50, 4326); |
| 239 | + TestPlace::factory()->create(['point' => $pointWithinPolygon]); |
| 240 | + TestPlace::factory()->create(['point' => $pointOutsidePolygon]); |
| 241 | + |
| 242 | + /** @var TestPlace[] $testPlacesNotWithinPolygon */ |
| 243 | + $testPlacesNotWithinPolygon = TestPlace::query() |
| 244 | + ->whereNotWithin('point', $polygon) |
| 245 | + ->get(); |
| 246 | + |
| 247 | + expect($testPlacesNotWithinPolygon)->toHaveCount(1); |
| 248 | +}); |
| 249 | + |
235 | 250 | it('filters by contains', function (): void {
|
236 | 251 | $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}', 4326);
|
237 | 252 | $pointWithinPolygon = new Point(0, 0, 4326);
|
|
249 | 264 | expect($testPlace2)->toBeNull();
|
250 | 265 | });
|
251 | 266 |
|
| 267 | +it('filters by not contains', function (): void { |
| 268 | + $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}', 4326); |
| 269 | + $pointWithinPolygon = new Point(0, 0, 4326); |
| 270 | + $pointOutsidePolygon = new Point(50, 50, 4326); |
| 271 | + TestPlace::factory()->create(['polygon' => $polygon]); |
| 272 | + |
| 273 | + $testPlace = TestPlace::query() |
| 274 | + ->whereNotContains('polygon', $pointWithinPolygon) |
| 275 | + ->first(); |
| 276 | + $testPlace2 = TestPlace::query() |
| 277 | + ->whereNotContains('polygon', $pointOutsidePolygon) |
| 278 | + ->first(); |
| 279 | + |
| 280 | + expect($testPlace)->toBeNull(); |
| 281 | + expect($testPlace2)->not->toBeNull(); |
| 282 | +}); |
| 283 | + |
252 | 284 | it('filters by touches', function (): void {
|
253 | 285 | $polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[0,-1],[0,0],[-1,0],[-1,-1]]]}', 4326);
|
254 | 286 | $pointTouchesPolygon = new Point(0, 0, 4326);
|
|
0 commit comments