Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Javascript implementation for easier porting #5

Merged
merged 8 commits into from
Aug 30, 2024

Conversation

mbalfour-amzn
Copy link
Contributor

Description of changes:
This library will have Javascript, Swift, and Kotlin implementations. However, for Swift and Kotlin there weren't any official polyline implementations to rely on, which was going to make porting this library difficult. This PR almost completely rewrites the internals of the Javascript library to contain its own polyline implementation so that no external dependencies are needed (other than geojson). The public API and tests remain the same and continue to pass. A lot of the implementation also simplified pretty significantly because most of the error checking was easier to perform during the encoding/decoding instead of before and afterwards. All three of the supported compression/decompression algorithms (Polyline5, Polyline6, and FlexiblePolyline) now also share the same implementation, just with different initialization data.

Testing:

  • Re-ran all the unit tests and verified they still passed.
  • Added a demo HTML page that draws the word "Polyline" on a world map to show how encoding/decoding APIs are used.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

javascript/src/polyline-types.ts Outdated Show resolved Hide resolved

compressLngLatArray(
lngLatArray: Array<Array<number>>,
/* parameters: CompressionParameters, */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this commented-out line of code be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, no, because it's still being passed to the function, it's just unused by the function, which is why it's commented out. It's implementation-specific on whether or not to use that parameter, FlexiblePolyline uses it but EncodedPolyline doesn't.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change this to parameters?: CompressionParameters, then I think the compiler won't complain when parameters is unused. But if that doesn't work, I'm good with leaving this as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, sadly it still complains with that. :( Good idea though!

Copy link

@cgalvan cgalvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does our coverage look on this module with the unit tests?


compressLngLatArray(
lngLatArray: Array<Array<number>>,
/* parameters: CompressionParameters, */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change this to parameters?: CompressionParameters, then I think the compiler won't complain when parameters is unused. But if that doesn't work, I'm good with leaving this as-is.

@mbalfour-amzn
Copy link
Contributor Author

How does our coverage look on this module with the unit tests?

Like this:

-----------------------|---------|----------|---------|---------|-------------------

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 97.9 92.3 100 97.86
src 97.14 92.3 100 97.05
data-compressor.ts 96.42 81.81 100 96.29 43,77
index.ts 97.36 100 100 97.29 34
polyline-types.ts 100 100 100 100
src/algorithm 98.01 92.3 100 97.97
decoder.ts 98.14 90 100 98.11 173
encoder.ts 97.87 93.75 100 97.82 56
src/compressors 100 100 100 100
flexible-polyline.ts 100 100 100 100
polyline.ts 100 100 100 100
----------------------- --------- ---------- --------- --------- -------------------

@mbalfour-amzn mbalfour-amzn merged commit da228b6 into main Aug 30, 2024
2 checks passed
@mbalfour-amzn mbalfour-amzn deleted the mbalfour/javascript-refactor branch August 30, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants