summaryrefslogtreecommitdiffstats
path: root/webapp/tests/utils_get_nearest_point.test.jsx
blob: 02ca29cc384d44aa641e149961918738fc21b86a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import assert from 'assert';
import * as CommonUtils from 'utils/commons.jsx';

describe('CommonUtils.getNearestPoint', function() {
    this.timeout(10000);
    it('should return nearest point', function() {
        for (const data of [
            {
                points: [{x: 30, y: 40}, {x: 50, y: 50}, {x: 100, y: 2}, {x: 500, y: 200}, {x: 110, y: 20}, {x: 10, y: 20}],
                pivotPoint: {x: 10, y: 20},
                nearestPoint: {x: 10, y: 20},
                nearestPointLte: {x: 10, y: 20}
            },
            {
                points: [{x: 50, y: 50}, {x: 100, y: 2}, {x: 500, y: 200}, {x: 110, y: 20}, {x: 100, y: 90}, {x: 30, y: 40}],
                pivotPoint: {x: 10, y: 20},
                nearestPoint: {x: 30, y: 40},
                nearestPointLte: {}
            },
            {
                points: [{x: 50, y: 50}, {x: 1, y: 1}, {x: 15, y: 25}, {x: 100, y: 2}, {x: 500, y: 200}, {x: 110, y: 20}],
                pivotPoint: {x: 10, y: 20},
                nearestPoint: {x: 15, y: 25},
                nearestPointLte: {x: 1, y: 1}
            }
        ]) {
            const nearestPoint = CommonUtils.getNearestPoint(data.pivotPoint, data.points);

            assert.equal(nearestPoint.x, data.nearestPoint.x);
            assert.equal(nearestPoint.y, data.nearestPoint.y);
        }
    });
});