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

Replace CustomPoint with extension methods on Point #1585

Conversation

rorystephenson
Copy link
Contributor

@rorystephenson rorystephenson commented Jul 14, 2023

The CustomPoint class predates dart extension methods. The name is confusing (custom in what sense, and why) and in looking at the implementation it became clear that it was essentially just adding extension methods.

Changing to a Point will avoid conversions in plugins which deal with libraries that use Point.

Code will work as-is without changes with the exception of the subtraction operator. Previously CustomPoint - CustomPoint did not trigger analyzer warnings but would cause a runtime exception. This is now replaced by subtract() extension methods which allow subtracting num from a Point and int from Point.


Issue #1522 prompted me to look at this and I believe it resolves that issue (we no longer add methods which are not runtime-safe to Point and Point already documents the potential runtime error with the * operator).

Note that the vast majority of changes are just renaming CustomPoint to Point and importing it.

Copy link
Member

@JaffaKetchup JaffaKetchup left a comment

Choose a reason for hiding this comment

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

LGTM, apart from these few nitpicks for consistency and to keep things concise.

lib/src/geo/crs.dart Outdated Show resolved Hide resolved
lib/src/layer/tile_layer/tile_layer.dart Outdated Show resolved Hide resolved
lib/src/layer/tile_layer/tile_range.dart Outdated Show resolved Hide resolved
lib/src/map/camera/camera.dart Outdated Show resolved Hide resolved
lib/src/map/camera/camera_constraint.dart Outdated Show resolved Hide resolved
lib/src/map/camera/camera_fit.dart Outdated Show resolved Hide resolved
lib/src/misc/point_extensions.dart Outdated Show resolved Hide resolved
lib/src/misc/private/bounds.dart Outdated Show resolved Hide resolved
@JaffaKetchup JaffaKetchup linked an issue Jul 16, 2023 that may be closed by this pull request
@rorystephenson
Copy link
Contributor Author

Nice catch on the redundant imports @JaffaKetchup !

First I started by removing the import 'dart:math' as math; imports but that didn't work well with some classes which had min/max getters in classes in some of the tile related code. So then I started removing the new import 'dart:math'; imports but this meant that Point was always prefixed with math which makes quite a mess. I think importing math with a prefix makes sense for methods like min/max and getters like pi but in the case of Point it is pretty unambiguous.

For that reason I've updated the imports to:

import 'dart:math' as math hide Point;
import 'dart:math' show Point;

WDYT?

@JaffaKetchup
Copy link
Member

It's less than ideal, I'm sure you'll agree, but OK for now!

Copy link
Member

@JaffaKetchup JaffaKetchup left a comment

Choose a reason for hiding this comment

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

LGTM I think. Would like another review though, if anyone can do it today!

@rorystephenson rorystephenson force-pushed the replace-custom-point-with-extension-methods-on-point branch from 02bf67b to 3471c44 Compare July 18, 2023 10:14
rorystephenson and others added 4 commits July 18, 2023 12:14
The CustomPoint class predates dart extension methods. The name is
confusing (custom in what sense, and why) and in looking at the
implementation it became clear that it was essentially just adding
extension methods.

Changing to a Point will avoid conversions in plugins which deal with
libraries that use Point.

Code will work as-is without changes with the exception of the
subtraction operator. Previously CustomPoint<int> - CustomPoint<double>
did not trigger analyzer warnings but would cause a runtime exception.
This is now replaced by subtract() extension methods which allow
subtracting num from a Point<double> and int from Point<int>.
Co-authored-by: 6y <tlserver6y@gmail.com>
@rorystephenson rorystephenson force-pushed the replace-custom-point-with-extension-methods-on-point branch from 3471c44 to c1545dc Compare July 18, 2023 10:14
Copy link
Collaborator

@mootw mootw left a comment

Choose a reason for hiding this comment

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

lgtm

@JaffaKetchup JaffaKetchup merged commit 1a17eb1 into fleaflet:master Jul 20, 2023
@rorystephenson rorystephenson deleted the replace-custom-point-with-extension-methods-on-point branch July 20, 2023 07:24
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.

[BUG] CustomPoint has potential cast exception at runtime
3 participants