Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Commit

Permalink
Issue #175 ongoing src/util folder ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwouaiebe committed Jul 23, 2021
1 parent 819c3c5 commit 7f9fcce
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 61 deletions.
2 changes: 1 addition & 1 deletion buildNumber.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "buildNumber" : "00382"}
{ "buildNumber" : "00386"}
2 changes: 1 addition & 1 deletion src/core/FileCompactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Tests ...
@------------------------------------------------------------------------------------------------------------------------------
*/

import { thePolylineEncoder } from '../util/PolylineEncoder.js';
import thePolylineEncoder from '../util/PolylineEncoder.js';
import theTravelNotesData from '../data/TravelNotesData.js';
import Travel from '../data/Travel.js';
import { ROUTE_EDITION_STATUS, ELEV, ZERO, ONE, TWO, INVALID_OBJ_ID, LAT_LNG, DISTANCE } from '../util/Constants.js';
Expand Down
2 changes: 1 addition & 1 deletion src/routeProviders/GraphHopperRouteProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Tests ...
@------------------------------------------------------------------------------------------------------------------------------
*/

import { thePolylineEncoder } from '../util/PolylineEncoder.js';
import thePolylineEncoder from '../util/PolylineEncoder.js';
import { ZERO, TWO, LAT, LNG, ELEVATION, LAT_LNG, HTTP_STATUS_OK, DISTANCE } from '../util/Constants.js';

const OUR_GRAPHHOPPER_LAT_LNG_ROUND = 5;
Expand Down
2 changes: 1 addition & 1 deletion src/routeProviders/MapboxRouteProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Tests ...
@------------------------------------------------------------------------------------------------------------------------------
*/

import { thePolylineEncoder } from '../util/PolylineEncoder.js';
import thePolylineEncoder from '../util/PolylineEncoder.js';
import { theOsrmTextInstructions } from '../routeProviders/OsrmTextInstructions.js';
import { ICON_LIST } from '../routeProviders/IconList.js';
import { ZERO, ONE, TWO, LAT_LNG, HTTP_STATUS_OK } from '../util/Constants.js';
Expand Down
2 changes: 1 addition & 1 deletion src/routeProviders/MapzenValhallaRouteProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Tests ...
@------------------------------------------------------------------------------------------------------------------------------
*/

import { thePolylineEncoder } from '../util/PolylineEncoder.js';
import thePolylineEncoder from '../util/PolylineEncoder.js';
import { ZERO, HTTP_STATUS_OK, DISTANCE } from '../util/Constants.js';

const OUR_MAPZEN_LAT_LNG_ROUND = 6;
Expand Down
2 changes: 1 addition & 1 deletion src/routeProviders/OpenRouteServiceRouteProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Tests ...
@------------------------------------------------------------------------------------------------------------------------------
*/

import { thePolylineEncoder } from '../util/PolylineEncoder.js';
import thePolylineEncoder from '../util/PolylineEncoder.js';
import { ZERO, ONE, TWO, LAT, LNG, ELEVATION, LAT_LNG, HTTP_STATUS_OK } from '../util/Constants.js';

const OUR_OPEN_ROUTE_LAT_LNG_ROUND = 5;
Expand Down
2 changes: 1 addition & 1 deletion src/routeProviders/OsrmRouteProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Tests ...
@------------------------------------------------------------------------------------------------------------------------------
*/

import { thePolylineEncoder } from '../util/PolylineEncoder.js';
import thePolylineEncoder from '../util/PolylineEncoder.js';
import { theOsrmTextInstructions } from '../routeProviders/OsrmTextInstructions.js';
import { ICON_LIST } from '../routeProviders/IconList.js';
import { ZERO, ONE, LAT_LNG, HTTP_STATUS_OK } from '../util/Constants.js';
Expand Down
99 changes: 45 additions & 54 deletions src/util/PolylineEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Changes:
- v2.1.0:
- created
Doc reviewed 20200803
- v3.0.0:
- Issue ♯175 : Private and static fields and methods are coming
Doc reviewed 20210723
Tests ...
*/

Expand Down Expand Up @@ -52,37 +54,6 @@ const OUR_NUMBER32 = 0x20;
const OUR_NUMBER63 = 0x3f;
const OUR_DOT5 = 0.5;

/**
@------------------------------------------------------------------------------------------------------------------------------
@function ourPython2Round
@desc This function round a number in the same way than Python 2
@param {number} value The value to round
@return {number} The rounded value
@private
@------------------------------------------------------------------------------------------------------------------------------
*/

function ourPython2Round ( value ) {
return Math.floor ( Math.abs ( value ) + OUR_DOT5 ) * ( ZERO <= value ? ONE : -ONE );
}

/**
@------------------------------------------------------------------------------------------------------------------------------
@class
@classdesc Encoder/decoder to encode or decode a polyline into a string.
Based on Mark McClure polyline encoder (more info needed...)
@see https://github.com/Project-OSRM/osrm-frontend/blob/master/WebContent/routing/OSRM.RoutingGeometry.js
@see https://github.com/graphhopper/directions-api-js-client/blob/master/src/GHUtil.js GHUtil.prototype.decodePath
@see https://developers.google.com/maps/documentation/utilities/polylinealgorithm
@see https://github.com/mapbox/polyline
@see {@link thePolylineEncoder} for the one and only one instance of this class
@hideconstructor
@------------------------------------------------------------------------------------------------------------------------------
*/
/*
Encoded Polyline Algorithm Format
Expand Down Expand Up @@ -148,18 +119,43 @@ Latitude Longitude Latitude Longitude Change In Change In Encoded Encoded
Encoded polyline: _p~iF~ps|U_ulLnnqC_mqNvxq`@
*/

class polylineEncoder {
/**
@------------------------------------------------------------------------------------------------------------------------------
@class PolylineEncoder
@classdesc Encoder/decoder to encode or decode a polyline into a string.
Based on Mark McClure polyline encoder (more info needed...)
@see https://github.com/Project-OSRM/osrm-frontend/blob/master/WebContent/routing/OSRM.RoutingGeometry.js
@see https://github.com/graphhopper/directions-api-js-client/blob/master/src/GHUtil.js GHUtil.prototype.decodePath
@see https://developers.google.com/maps/documentation/utilities/polylinealgorithm
@see https://github.com/mapbox/polyline
@see {@link thePolylineEncoder} for the one and only one instance of this class
@hideconstructor
@------------------------------------------------------------------------------------------------------------------------------
*/

class PolylineEncoder {

/**
This function round a number in the same way than Python 2
@param {number} value The value to round
@return {number} The rounded value
@private
*/

static #python2Round ( value ) {
return Math.floor ( Math.abs ( value ) + OUR_DOT5 ) * ( ZERO <= value ? ONE : -ONE );
}

constructor ( ) {
Object.freeze ( this );
}

/*
/**
encode an array of coordinates to a string ( coordinates can be 1d or 2d or 3d or more...)
@param {array.<array.<number>>} coordinates the coordinates to encode
@param {Array.<number>} precisions an array with the precision to use for each dimension
@return {string} the encoded coordinates
*/

Expand All @@ -172,8 +168,8 @@ class polylineEncoder {
let factors = Array.from ( precisions, precision => Math.pow ( OUR_NUMBER10, precision ) );

function encodeDelta ( current, previous, factorD ) {
let currentCoordRound = ourPython2Round ( current * factorD );
let previousCoordRound = ourPython2Round ( previous * factorD );
let currentCoordRound = PolylineEncoder.#python2Round ( current * factorD );
let previousCoordRound = PolylineEncoder.#python2Round ( previous * factorD );
let coordinateDelta = currentCoordRound - previousCoordRound;
/* eslint-disable no-bitwise */
coordinateDelta <<= ONE;
Expand Down Expand Up @@ -205,12 +201,10 @@ class polylineEncoder {
return output;
}

/*
/**
decode a string into an array of coordinates (coordinates can be 1d, 2d, 3d or more...)
@param {string } encodedString the string to decode
@param {Array.<number>} precisions an array with the precision to use for each dimension
@return {array.<array.<number>>} the decoded coordinates
*/

Expand Down Expand Up @@ -252,23 +246,20 @@ class polylineEncoder {
}
}

const OUR_POLYLINE_ENCODER = new polylineEncoder ( );

export {
/**
@------------------------------------------------------------------------------------------------------------------------------
/**
@--------------------------------------------------------------------------------------------------------------------------
@desc The one and only one instance of PolylineEncoder class
@type {PolylineEncoder}
@constant
@global
@desc The one and only one instance of polylineEncoder class
@type {PolylineEncoder}
@constant
@global
@------------------------------------------------------------------------------------------------------------------------------
*/

@--------------------------------------------------------------------------------------------------------------------------
*/
const thePolylineEncoder = new PolylineEncoder ( );

OUR_POLYLINE_ENCODER as thePolylineEncoder
};
export default thePolylineEncoder;

/*
--- End of PolylineEncoder.js file --------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 7f9fcce

Please sign in to comment.