-
-
Notifications
You must be signed in to change notification settings - Fork 871
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monomorphize projection call and avoid Num.clamp. Saves another 22% C…
…PU cycles on the UI thread for my test-case.
- Loading branch information
Showing
4 changed files
with
56 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flutter_map/src/geo/crs.dart'; | ||
import 'package:flutter_map/src/map/camera/camera.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
|
||
Offset getOffset(MapCamera camera, Offset origin, LatLng point) { | ||
final crs = camera.crs; | ||
final zoomScale = crs.scale(camera.zoom); | ||
final (x, y) = crs.latLngToXY(point, zoomScale); | ||
return Offset(x - origin.dx, y - origin.dy); | ||
} | ||
|
||
List<Offset> getOffsets(MapCamera camera, Offset origin, List<LatLng> points) { | ||
// Critically create as little garbage as possible. This is called on every frame. | ||
final crs = camera.crs; | ||
final zoomScale = crs.scale(camera.zoom); | ||
|
||
final ox = -origin.dx; | ||
final oy = -origin.dy; | ||
final len = points.length; | ||
|
||
// Optimization: monomorphize the Epsg3857-case to save the virtual function overhead. | ||
if (crs is Epsg3857) { | ||
final Epsg3857 epsg3857 = crs; | ||
final v = List<Offset>.filled(len, Offset.zero); | ||
for (int i = 0; i < len; ++i) { | ||
final (x, y) = epsg3857.latLngToXY(points[i], zoomScale); | ||
v[i] = Offset(x + ox, y + oy); | ||
} | ||
return v; | ||
} | ||
|
||
final v = List<Offset>.filled(len, Offset.zero); | ||
for (int i = 0; i < len; ++i) { | ||
final (x, y) = crs.latLngToXY(points[i], zoomScale); | ||
v[i] = Offset(x + ox, y + oy); | ||
} | ||
return v; | ||
} |