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

Fixed-point pixel accurate 2D geometry with minimal approximations.

Changelog #

0.1.4 #

Features:

  • Added Rect.size to get the width and height of a rectangle as a Pos:

    Rect.fromLTWH(5, 5, 2, 2).size; // Pos(2, 2)
    

0.1.3+2 #

No public API changes.

0.1.3+1 #

No public API changes.

0.1.3 #

Features:

  • Added optional parameter size to <Pos>.toRect when converting a position:

    Pos(5, 5).toRect(size: Pos(2, 2)); // Rect.fromLTWH(5, 5, 2, 2)
    
  • Added <Pos>.toSize to convert a position, optionally with an offset:

    Pos(5, 5).toSize(); // Rect.fromLTWH(0, 0, 5, 5)
    Pos(5, 5).toSize(Pos(2, 2)); // Rect.fromLTWH(2, 2, 5, 5)
    
  • Added Rect.fromWH to create a width, height, and optional offset:

    Rect.fromWH(5, 5); // Rect.fromLTWH(0, 0, 5, 5)
    Rect.fromWH(5, 5, Pos(2, 2)); // Rect.fromLTWH(2, 2, 5, 5)
    
  • Added <Rect>.normalize() to convert a rectangle to one with positive width and height:

    Rect.fromLTRB(5, 5, 3, 3).normalize(); // Rect.fromLTRB(3, 3, 5, 5)
    Rect.fromLTRB(3, 3, -2, -2).normalize(); // Rect.fromLTRB(-2, -2, 3, 3)
    

0.1.2 #

Features:

  • Added Pos.truncate to convert doubles to an integer position:

    Pos.truncate(5.5, 5.5); // Pos(5, 5)
    
  • Added Pos.floor to convert doubles to an integer position, rounding down:

    Pos.floor(5.5, 5.5); // Pos(5, 5)
    
  • Added Pos.byDistanceTo to create a comparator that sorts positions based on distance to a given position:

    final comparator = Pos.byDistanceTo(Pos(5, 5));
    [Pos(0, 0), Pos(1, 1), Pos(2, 2)].sort(comparator); // [Pos(2, 2), Pos(1, 1), Pos(0, 0)]
    
  • Added <Pos>.map to apply a function to each component of a position:

    Pos(5, 5).map((x) => x * 2); // Pos(10, 10)
    
  • Added <Pos>.toList to convert a position to a list of integers:

    Pos(5, 5).toList(); // [5, 5]
    
  • Added <Pos>.xy to get the x and y components of a position as a tuple:

    Pos(5, 5).xy; // (5, 5)
    

0.1.1+1 #

Deprecations:

  • Deprecated Direction.values in favor of the identical Direction.all:

    - for (final dir in Direction.values) {
    + for (final dir in Direction.all) {
    

Misc:

  • Added dartdoc categories for upstream use in package:sector.

0.1.1 #

Features:

Most new additions were to the Pos class:

  • Added vectorLine as a faster Line function (alternative to bresenham):

    vectorLine(Pos(0, 0), Pos(2, 2)); // [Pos(0, 0), Pos(1, 1), Pos(2, 2)]
    
  • Added diagonal distance to compliment manhattan and chebyshev distances:

    Pos(0, 0).distanceTo(Pos(3, 4), diagonal); // 5.0
    
  • Added <Pos>.inflate, which uses the position as the center of a rectangle and inflates it by the given delta Pos offset:

    Pos(5, 5).inflate(Pos(2, 2)); // Rect.fromLTRB(3, 3, 7, 7)
    
  • Added <Pos>.toRect() to convert a position to a rectangle with a size of 1x1:

    Pos(5, 5).toRect(); // Rect.fromLTWH(5, 5, 1, 1)
    
  • Added <Pos>.max, <Pos>.min, and <Pos>.clamp to get the maximum, minimum, and clamped position between two positions:

    Pos(5, 5).max(Pos(3, 3)); // Pos(5, 5)
    Pos(5, 5).min(Pos(3, 3)); // Pos(3, 3)
    Pos(5, 5).clamp(Pos(3, 3), Pos(7, 7)); // Pos(5, 5)
    
  • Added <Pos>.approximateNormalized, which returns a new position with the

  • same direction but a magnitude as close as possible to 1, which is the best

  • possible for fixed-point positions:

    Pos(10, 20).approximateNormalized; // Pos(1, 2)
    
  • Added <Pos>.dot and <Pos>.cross to calculate the dot and cross products between two positions:

    Pos(1, 2).dot(Pos(3, 4)); // 11
    Pos(1, 2).cross(Pos(3, 4)); // -2
    
  • Added missing core operators: ~/, %, ~, <<, >>.

New changes to the Rect class:

  • Added <Rect>.inflate and <Rect>.deflate, which, given a delta Pos offset inflates or deflates the rectangle by that amount:

    final rect = Rect.fromLTWH(0, 0, 10, 10);
    rect.inflate(Pos(2, 2)); // Rect.fromLTRB(-2, -2, 12, 12)
    rect.deflate(Pos(2, 2)); // Rect.fromLTRB(2, 2, 8, 8)
    

Other new features:

  • Added a new extension on (int, int) to convert a tuple to a Pos:

    (5, 5).toPos(); // Pos(5, 5)
    
  • Added approximateSqrt, to calculate the integer square root of a number without rounding:

    approximateSqrt(10); // 3
    

0.1.0 #

🎉 Initial release 🎉

4
likes
0
pub points
2%
popularity

Publisher

verified publisherlurey.dev

Fixed-point pixel accurate 2D geometry with minimal approximations.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta

More

Packages that depend on lodim