lodim 0.1.0 copy "lodim: ^0.1.0" to clipboard
lodim: ^0.1.0 copied to clipboard

Fixed-point pixel accurate 2D geometry without approximations.

example/example.dart

// ignore_for_file: avoid_print, avoid_redundant_argument_values

import 'package:lodim/lodim.dart';

void main() {
  final pos = Pos(4, 2);
  final direction = Direction.right;
  print(pos + direction); // => Pos(5, 2)
  print(pos + direction * 3); // => Pos(7, 2)

  final rect = Rect.fromLTRB(4, 2, 7, 4);
  print(rect.topLeft); // => Pos(4, 2)
  print(rect.bottomRight); // => Pos(7, 4)
  print(rect.width); // => 3
  print(rect.height); // => 2

  final other = Rect.fromLTRB(6, 3, 8, 5);
  print(rect.contains(Pos(5, 3))); // => true
  print(rect.intersect(other)); // => Rect.fromLTRB(6, 3, 7, 4)
  for (final edge in rect.edges) {
    print(edge); // => Pos(x, y)
  }

  final a = Pos(10, 20);
  final b = Pos(30, 40);
  print(a.distanceTo(b, using: euclideanSquared)); // => 500
  print(a.distanceTo(b, using: manhattan)); // => 40

  final rotated = pos.rotate90();
  print(rotated); // => Pos(-2, 4)
  print(Direction.right); // => Pos(1, 0)

  for (final p in a.lineTo(b)) {
    print(p);
  }
}
3
likes
0
pub points
41%
popularity

Publisher

verified publisherlurey.dev

Fixed-point pixel accurate 2D geometry without approximations.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta

More

Packages that depend on lodim