From 6c644186ba3f43dbb01a9192d2dd5ccf0281777d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Sun, 27 Nov 2016 21:45:53 +0100 Subject: [PATCH] Add test case for ol.geom.flat.contains --- test/spec/ol/geom/flat/contains.test.js | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/spec/ol/geom/flat/contains.test.js diff --git a/test/spec/ol/geom/flat/contains.test.js b/test/spec/ol/geom/flat/contains.test.js new file mode 100644 index 0000000000..68f4e1b0dc --- /dev/null +++ b/test/spec/ol/geom/flat/contains.test.js @@ -0,0 +1,42 @@ +goog.provide('ol.test.geom.flat.contains'); + +goog.require('ol.geom.flat.contains'); + + +describe('ol.geom.flat.contains', function() { + + describe('with simple data', function() { + + var flatCoordinatesSimple = [0, 0, 1, 0, 1, 1, 0, 1]; + var flatCoordinatesNonSimple = [0, 0, 4, 0, 4, 3, 1, 3, 1, 2, 3, 2, 3, 1, 2, 1, 2, 4, 0, 4]; + + describe('ol.geom.flat.closest.getMaxSquaredDelta', function() { + + it('returns true for point inside a simple polygon', function() { + expect(ol.geom.flat.contains.linearRingContainsXY( + flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 0.5, 0.5)).to.be(true); + }); + + it('returns false for point outside a simple polygon', function() { + expect(ol.geom.flat.contains.linearRingContainsXY( + flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 1.5, 1.5)).to.be(false); + }); + + it('returns true for point inside a non-simple polygon', function() { + expect(ol.geom.flat.contains.linearRingContainsXY( + flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1, 1)).to.be(true); + }); + + it('returns true for point inside an overlap of a non-simple polygon', function() { + expect(ol.geom.flat.contains.linearRingContainsXY( + flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1.5, 2.5)).to.be(true); + }); + + it('returns false for a point inside a hole of a non-simple polygon', function() { + expect(ol.geom.flat.contains.linearRingContainsXY( + flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 2.5, 1.5)).to.be(false); + }); + + }); + }); +});