Skip to content

Commit

Permalink
refactor: reduce complexity and redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
Seli0303 committed Jun 13, 2024
1 parent e148ff9 commit eda4f02
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,21 @@ class OptimizationBuilder {
let lng = 0
let ele = 0
while (index < len) {
let b
let shift = 0
let result = 0
do {
b = encodedPolyline.charAt(index++).charCodeAt(0) - 63 // finds ascii
// and subtract it by 63
result |= (b & 0x1f) << shift
shift += 5
} while (b >= 0x20)
let decodedLine = this.decodeLine(encodedPolyline, index)
result = decodedLine.result
index = decodedLine.index

lat += ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1))
shift = 0
result = 0
do {
b = encodedPolyline.charAt(index++).charCodeAt(0) - 63
result |= (b & 0x1f) << shift
shift += 5
} while (b >= 0x20)
decodedLine = this.decodeLine(encodedPolyline, index)
result = decodedLine.result
index = decodedLine.index
lng += ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1))

if (includeElevation) {
shift = 0
result = 0
do {
b = encodedPolyline.charAt(index++).charCodeAt(0) - 63
result |= (b & 0x1f) << shift
shift += 5
} while (b >= 0x20)
decodedLine = this.decodeLine(encodedPolyline, index)
result = decodedLine.result
index = decodedLine.index
ele += ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1))
}
try {
Expand All @@ -95,5 +82,18 @@ class OptimizationBuilder {
}
return points
}

decodeLine(encodedPolyline, index){
let b
let shift = 0
let result = 0
do {
b = encodedPolyline.charAt(index++).charCodeAt(0) - 63 // finds ascii
// and subtract it by 63
result |= (b & 0x1f) << shift
shift += 5
} while (b >= 0x20)
return {result, index}
}
}
export default OptimizationBuilder

0 comments on commit eda4f02

Please sign in to comment.