Skip to content
New issue

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

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

Already on GitHub? # to your account

Reduce unnecessary casts, use convert when unsafe #1357

Merged
merged 2 commits into from
Sep 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions example/lib/pages/scale_layer_plugin_option.dart
Original file line number Diff line number Diff line change
@@ -101,18 +101,16 @@ class ScalePainter extends CustomPainter {

const sizeForStartEnd = 4;
final paddingLeft =
padding == null ? 0 : padding!.left + sizeForStartEnd / 2;
var paddingTop = padding == null ? 0 : padding!.top;
padding == null ? 0.0 : padding!.left + sizeForStartEnd / 2;
var paddingTop = padding == null ? 0.0 : padding!.top;

final textSpan = TextSpan(style: textStyle, text: text);
final textPainter =
TextPainter(text: textSpan, textDirection: TextDirection.ltr)..layout();
textPainter.paint(
canvas,
Offset(width / 2 - textPainter.width / 2 + paddingLeft,
paddingTop as double));
textPainter.paint(canvas,
Offset(width / 2 - textPainter.width / 2 + paddingLeft, paddingTop));
paddingTop += textPainter.height;
final p1 = Offset(paddingLeft as double, sizeForStartEnd + paddingTop);
final p1 = Offset(paddingLeft, sizeForStartEnd + paddingTop);
final p2 = Offset(paddingLeft + width, sizeForStartEnd + paddingTop);
// draw start line
canvas.drawLine(Offset(paddingLeft, paddingTop),
6 changes: 3 additions & 3 deletions lib/src/geo/crs/crs.dart
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ abstract class Crs {
}

/// Scale to Zoom function.
num zoom(double scale) {
double zoom(double scale) {
return math.log(scale / 256) / math.ln2;
}

@@ -296,7 +296,7 @@ class Proj4Crs extends Crs {

/// Scale to Zoom function.
@override
num zoom(double scale) {
double zoom(double scale) {
// Find closest number in _scales, down
final downScale = _closestElement(_scales, scale);
if (downScale == null) {
@@ -305,7 +305,7 @@ class Proj4Crs extends Crs {
final downZoom = _scales.indexOf(downScale);
// Check if scale is downScale => return array index
if (scale == downScale) {
return downZoom;
return downZoom.toDouble();
}
// Interpolate
final nextZoom = downZoom + 1;
56 changes: 29 additions & 27 deletions lib/src/geo/latlng_bounds.dart
Original file line number Diff line number Diff line change
@@ -14,36 +14,38 @@ class LatLngBounds {
}

LatLngBounds.fromPoints(List<LatLng> points) {
if (points.isNotEmpty) {
num? minX;
num? maxX;
num? minY;
num? maxY;

for (final point in points) {
final num x = point.longitudeInRad;
final num y = point.latitudeInRad;

if (minX == null || minX > x) {
minX = x;
}

if (minY == null || minY > y) {
minY = y;
}

if (maxX == null || maxX < x) {
maxX = x;
}

if (maxY == null || maxY < y) {
maxY = y;
}
if (points.isEmpty) {
return;
}

double minX = 180;
double maxX = -180;
double minY = 90;
double maxY = -90;

for (final point in points) {
final double x = point.longitude;
final double y = point.latitude;

if (minX > x) {
minX = x;
}

_sw = LatLng(radianToDeg(minY as double), radianToDeg(minX as double));
_ne = LatLng(radianToDeg(maxY as double), radianToDeg(maxX as double));
if (minY > y) {
minY = y;
}

if (maxX < x) {
maxX = x;
}

if (maxY < y) {
maxY = y;
}
}

_sw = LatLng(minY, minX);
_ne = LatLng(maxY, maxX);
}

/// Expands bounding box by [latlng] coordinate point. This method mutates
16 changes: 5 additions & 11 deletions lib/src/layer/circle_layer.dart
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ class CircleMarker {
final Color borderColor;
final bool useRadiusInMeter;
Offset offset = Offset.zero;
num realRadius = 0;
double realRadius = 0;
CircleMarker({
required this.point,
required this.radius,
@@ -72,23 +72,17 @@ class CirclePainter extends CustomPainter {
..style = PaintingStyle.fill
..color = circle.color;

_paintCircle(
canvas,
circle.offset,
circle.useRadiusInMeter ? circle.realRadius as double : circle.radius,
paint);
_paintCircle(canvas, circle.offset,
circle.useRadiusInMeter ? circle.realRadius : circle.radius, paint);

if (circle.borderStrokeWidth > 0) {
final paint = Paint()
..style = PaintingStyle.stroke
..color = circle.borderColor
..strokeWidth = circle.borderStrokeWidth;

_paintCircle(
canvas,
circle.offset,
circle.useRadiusInMeter ? circle.realRadius as double : circle.radius,
paint);
_paintCircle(canvas, circle.offset,
circle.useRadiusInMeter ? circle.realRadius : circle.radius, paint);
}
}

2 changes: 1 addition & 1 deletion lib/src/map/flutter_map_state.dart
Original file line number Diff line number Diff line change
@@ -570,7 +570,7 @@ class FlutterMapState extends MapGestureMixin
double getScaleZoom(double scale, double? fromZoom) {
final crs = options.crs;
fromZoom = fromZoom ?? _zoom;
return crs.zoom(scale * crs.scale(fromZoom)) as double;
return crs.zoom(scale * crs.scale(fromZoom));
}

Bounds? getPixelWorldBounds(double? zoom) {