geospatialdraw
Version:
Geospatial Map Drawing Library
185 lines • 6.98 kB
JavaScript
"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([
[
[ ],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[
[ ],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[
[ ],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[
[ ],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[
[ ],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[
[ ],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[
[ ],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[ ],
[ ],
]));
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([
[ ],
[ ],
[ ],
]));
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([
[
[ ],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[
[ ],
[-2.0027, -1.1563],
[-2.0027, 1.1563],
[ ],
[ ],
[ ],
[ ],
],
]));
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([
[
[ ],
[ ],
[ ],
[ ],
],
]));
var actual = shapeDetector.shapeFromFeature(feature);
(0, chai_1.expect)(actual).to.equal('Polygon');
});
});
});
//# sourceMappingURL=shape-detector.spec.js.map