UNPKG

geospatialdraw

Version:
185 lines 6.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var chai_1 = require("chai"); var shape_detector_1 = require("./shape-detector"); var ol_1 = require("ol"); var geom_1 = require("ol/geom"); describe('ShapeDetector', function () { var shapeDetector = new shape_detector_1.default(); beforeEach(function () { shapeDetector = new shape_detector_1.default(); }); describe('isBoundingBoxFeature', function () { it('Clockwise From Bottom Left', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [0, 0], [0, 1], [1, 1], [1, 0], [0, 0], ], ])); var actual = shapeDetector.isBoundingBoxFeature(feature); (0, chai_1.expect)(actual).to.equal(true); }); it('Clockwise From Top Left', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [0, 1], [1, 1], [1, 0], [0, 0], [0, 1], ], ])); var actual = shapeDetector.isBoundingBoxFeature(feature); (0, chai_1.expect)(actual).to.equal(true); }); it('Clockwise From Top Right', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [1, 1], [1, 0], [0, 0], [0, 1], [1, 1], ], ])); var actual = shapeDetector.isBoundingBoxFeature(feature); (0, chai_1.expect)(actual).to.equal(true); }); it('Clockwise Bottom Right', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [1, 0], [0, 0], [0, 1], [1, 1], [1, 0], ], ])); var actual = shapeDetector.isBoundingBoxFeature(feature); (0, chai_1.expect)(actual).to.equal(true); }); it('Old Editor Bounding Box', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [37.15079928954003, 35.252426841484066], [38.8031053182774, 35.252426841484066], [38.8031053182774, 34.092763897976624], [37.15079928954003, 34.092763897976624], [37.15079928954003, 35.252426841484066], ], ])); var actual = shapeDetector.isBoundingBoxFeature(feature); (0, chai_1.expect)(actual).to.equal(true); }); it('Random Bounding Box', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [-103.23955535888672, 41.966400146484375], [-102.4200439453125, 41.966400146484375], [-102.4200439453125, 42.591590881347656], [-103.23955535888672, 42.591590881347656], [-103.23955535888672, 41.966400146484375], ], ])); var actual = shapeDetector.isBoundingBoxFeature(feature); (0, chai_1.expect)(actual).to.equal(true); }); it('Not a bounding box first and last coordinates', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [1, 0.1], [0, 0], [0, 1], [1, 1], [1, 0.1], ], ])); var actual = shapeDetector.isBoundingBoxFeature(feature); (0, chai_1.expect)(actual).to.equal(false); }); it('Not a bounding box middle coordinate', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [1, 0], [0, 1], [0, 1], [1, 1], [1, 0], ], ])); var actual = shapeDetector.isBoundingBoxFeature(feature); (0, chai_1.expect)(actual).to.equal(false); }); }); describe('shapeFromFeature', function () { it('Line', function () { var feature = new ol_1.Feature(new geom_1.LineString([ [5, 5], [0, 0], ])); var actual = shapeDetector.shapeFromFeature(feature); (0, chai_1.expect)(actual).to.equal('Line'); }); it('Line closed loop', function () { var feature = new ol_1.Feature(new geom_1.LineString([ [5, 5], [0, 0], [5, 5], ])); var actual = shapeDetector.shapeFromFeature(feature); (0, chai_1.expect)(actual).to.equal('Line'); }); it('Bounding Box', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [0.212, 0.389], [0.212, 0.503], [0.513, 0.503], [0.513, 0.389], [0.212, 0.389], ], ])); var actual = shapeDetector.shapeFromFeature(feature); (0, chai_1.expect)(actual).to.equal('Bounding Box'); }); it('Point Radius', function () { var feature = new ol_1.Feature(new geom_1.Point([0, 0])); feature.set('buffer', 1); feature.set('bufferUnit', 'meters'); var actual = shapeDetector.shapeFromFeature(feature); (0, chai_1.expect)(actual).to.equal('Point Radius'); }); it('Polygon near circular', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [0.0, -2.3125], [-2.0027, -1.1563], [-2.0027, 1.1563], [0.0, 2.3125], [2.0027, 1.1563], [2.0127, -1.1673], [0.0, -2.3125], ], ])); var actual = shapeDetector.shapeFromFeature(feature); (0, chai_1.expect)(actual).to.equal('Polygon'); }); it('Polygon triangle', function () { var feature = new ol_1.Feature(new geom_1.Polygon([ [ [0.0, 0.0], [3.0, 3.0], [3.0, 0.0], [0.0, 0.0], ], ])); var actual = shapeDetector.shapeFromFeature(feature); (0, chai_1.expect)(actual).to.equal('Polygon'); }); }); }); //# sourceMappingURL=shape-detector.spec.js.map