lodim 0.1.1
lodim: ^0.1.1 copied to clipboard
Fixed-point pixel accurate 2D geometry with minimal approximations.
Changelog #
0.1.1 #
Features #
Pos
-
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:
~/,%,~,<<,>>.
Rect
-
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)
Misc
-
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 🎉