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

Add zoomIn, zoomOut and zoomOut to Scalable2i #121

Closed
navispatial opened this issue Jun 14, 2022 · 1 comment
Closed

Add zoomIn, zoomOut and zoomOut to Scalable2i #121

navispatial opened this issue Jun 14, 2022 · 1 comment
Labels
enhancement New feature or request 🌐 geobase Related to the code package "geobase"

Comments

@navispatial
Copy link
Member

Scalable base class:

  /// Zooms in by one.
  Scalable zoomIn() => Scalable(zoom: zoom + 1);

  /// Zooms out by one.
  /// 
  /// The minimum value for [zoom] of the returned scalable object is 0.
  Scalable zoomOut() => Scalable(zoom: math.max(zoom - 1, 0));

  /// Zooms to the [zoom] level (a positive number).
  Scalable zoomTo(covariant num zoom) => Scalable(zoom: zoom);

Scalable2i:

  @override
  Scalable2i zoomIn() => Scalable2i(
        zoom: zoom + 1,
        x: x << 1,
        y: y << 1,
      );

  @override
  Scalable2i zoomOut() => zoom == 0
      ? this
      : Scalable2i(
          zoom: zoom - 1,
          x: x >> 1,
          y: y >> 1,
        );

  @override
  Scalable2i zoomTo(int zoom) {
    assert(zoom >= 0, 'Zoom must be >= 0');
    if (this.zoom == zoom) {
      return this;
    }
    final shift = zoom - this.zoom;
    return shift > 0
        ? Scalable2i(
            zoom: zoom,
            x: x << shift,
            y: y << shift,
          )
        : Scalable2i(
            zoom: zoom,
            x: x >> shift.abs(),
            y: y >> shift.abs(),
          );
  }
@navispatial navispatial added enhancement New feature or request 🌐 geobase Related to the code package "geobase" labels Jun 14, 2022
@navispatial
Copy link
Member Author

Implemented by beta 0.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 🌐 geobase Related to the code package "geobase"
Projects
None yet
Development

No branches or pull requests

1 participant