Skip to content

Commit

Permalink
fix zig-zag decoding
Browse files Browse the repository at this point in the history
To make bitwise operations platform independent the
[docs](https://dart.dev/guides/language/numbers#what-should-you-do)
recommend coercing to signed 32 bit integers.

Fixes #7
  • Loading branch information
blaugold authored and greensopinion committed Jul 28, 2022
1 parent 0c8706b commit 48ea150
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/src/model/geometry_decoding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int _decodeCommand(int command) => command & 0x7;
int _decodeCommandLength(int command) => command >> 3;

@pragma('vm:prefer-inline')
int _decodeZigZag(int value) => (value >> 1) ^ -(value & 1);
int _decodeZigZag(int value) => ((value >> 1) ^ -(value & 1)).toSigned(32);

Iterable<TilePoint> decodePoints(List<int> geometry) sync* {
final it = geometry.iterator;
Expand Down
2 changes: 1 addition & 1 deletion test/src/model/geometry_decoding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const closePath = 0x7;

int command(int command, int length) => length << 3 | command;

int zigZag(int n) => (n << 1) ^ (n >> 31);
int zigZag(int n) => ((n << 1) ^ (n >> 31)).toSigned(32);

void main() {
final uiGeometry = UiGeometry();
Expand Down

0 comments on commit 48ea150

Please sign in to comment.