lodim 0.1.6+6
lodim: ^0.1.6+6 copied to clipboard
Fixed-point pixel accurate 2D geometry with minimal approximations.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
0.1.6+6 #
- Bumped Dart to
^3.8.0.
0.1.6+5 #
- Update dependency ranges.
0.1.6+4 #
- Exposed some functions through
package:quirk.
0.1.6+3 #
- Bumped Dart to
^3.7.0.
0.1.6+2 #
- Merged into the
pub.luery.devmonorepo.
0.1.6+1 #
Fixes a mistake where methods were not renamed correctly.
The last release was published for only minutes, so hopefully this is fine!
0.1.6 #
Features:
-
Added additional functions for checking 1D and 2D collections:
checkRectangular1D&assertRectangular1DcheckRectangular2D&assertRectangular2D
0.1.5 #
Features:
-
Added top-level functions to perform bulk-
Posbased operations.While this library will not ship a grid implementation, it is no doubt useful in the context of
PosandRectto be able to make bulk operations on grid-like objects using these functions. There are two implementations of each function - one that uses callback functions, and one that operates on linear memory in row-major order:Callback-based Linear memory getRectgetRectLinearfillRectfillRectLinearfillRectFromfillRectFromLinearcopyRectcopyRectLinear -
Added
checkPositive,assertPositive, andassertNonNegativeas top-level methods to assert that a value is positive (>= 0), or non-negative (> 0); these methods return the value if it passes the check or throws an exception otherwise:checkPositive(5); // 5 assertPositive(5); // 5 assertNonNegative(5); // 5 -
Added
Pos.fromXYas an inverse of<Pos>.xyto create a position from a tuple:Pos.fromXY(5, 5); // Pos(5, 5) -
Added
Pos.fromRowMajorandPos.toRowMajorto convert a position to and from a row-major index:Pos.fromRowMajor(5, 3, 10); // Pos(5, 3) Pos(5, 3).toRowMajor(10); // 35 -
Added
Pos.fromListas an inverse of<Pos>.toListto create a position from a list of integers, optionally with a start index:Pos.fromList([5, 5]); // Pos(5, 5) Pos.fromList([1, 2, 3], 1); // Pos(2, 3)In addition, added
unsafevariants of these methods that do not check the bounds of the list:Pos.fromListUnsafe([5, 5]); // Pos(5, 5) Pos.fromListUnsafe([1, 2, 3], 1); // Pos(2, 3) -
Tweaked
<Pos>.toListto support writing to an existing list instead of allocating a new one:Pos(5, 5).toList([0, 0], 1); // [0, 5, 5]In addition, added
unsafevariants of these methods that do not check the bounds of the list:Pos(5, 5).toListUnsafe([0, 0], 1); // [0, 5, 5]
Deprecations:
-
The extension
IntPairhas been deprecated in favor ofPos.fromXY:- (5, 5).toPos(); + Pos.fromXY(5, 5); -
The following functions have been renamed (the originals are deprecated):
Replacement Original distanceSquaredeuclideanSquareddistanceApproximateeuclideanApproximatedistanceManhattanmanhattandistanceChebyshevchebyshevdistanceDiagonaldiagonallineBresenhambresenhamlineVectorvectorLine<Pos>.lineTo<Pos>.pathTo
0.1.4 #
Features:
-
Added
Rect.sizeto get the width and height of a rectangle as aPos: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
sizeto<Pos>.toRectwhen converting a position:Pos(5, 5).toRect(size: Pos(2, 2)); // Rect.fromLTWH(5, 5, 2, 2) -
Added
<Pos>.toSizeto 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.fromWHto 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.truncateto convert doubles to an integer position:Pos.truncate(5.5, 5.5); // Pos(5, 5) -
Added
Pos.floorto convert doubles to an integer position, rounding down:Pos.floor(5.5, 5.5); // Pos(5, 5) -
Added
Pos.byDistanceToto 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>.mapto apply a function to each component of a position:Pos(5, 5).map((x) => x * 2); // Pos(10, 10) -
Added
<Pos>.toListto convert a position to a list of integers:Pos(5, 5).toList(); // [5, 5] -
Added
<Pos>.xyto 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.valuesin favor of the identicalDirection.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
vectorLineas a fasterLinefunction (alternative tobresenham):vectorLine(Pos(0, 0), Pos(2, 2)); // [Pos(0, 0), Pos(1, 1), Pos(2, 2)] -
Added
diagonaldistance to complimentmanhattanandchebyshevdistances: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 deltaPosoffset: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>.clampto 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>.dotand<Pos>.crossto 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>.inflateand<Rect>.deflate, which, given a deltaPosoffset 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 aPos:(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 🎉