2023-09-21 22:37:12 +00:00
|
|
|
// Dart has a habit of using double-inclusive bounds,
|
|
|
|
// and I strongly prefer half-open bounds
|
|
|
|
//
|
|
|
|
// So: Here's a reimplementation of the geometry I need
|
2023-09-21 23:11:34 +00:00
|
|
|
import 'package:dartterm/skreek.dart';
|
|
|
|
|
2023-09-21 22:37:12 +00:00
|
|
|
class Size {
|
|
|
|
final int dx;
|
|
|
|
final int dy;
|
|
|
|
|
|
|
|
Size(this.dx, this.dy) {
|
|
|
|
assert(dx >= 0);
|
|
|
|
assert(dy >= 0);
|
|
|
|
}
|
2023-09-21 23:11:34 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "$dx x $dy";
|
|
|
|
}
|
2023-09-21 22:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Offset {
|
|
|
|
final int x;
|
|
|
|
final int y;
|
|
|
|
|
|
|
|
const Offset(this.x, this.y);
|
2023-09-21 23:11:34 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "@($x, $y)";
|
|
|
|
}
|
2023-09-21 22:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Rect {
|
|
|
|
final int x0;
|
|
|
|
final int y0;
|
|
|
|
final int dx;
|
|
|
|
final int dy;
|
|
|
|
|
|
|
|
int get x1 => x0 + dx;
|
|
|
|
int get y1 => y0 + dy;
|
|
|
|
|
|
|
|
Rect(this.x0, this.y0, this.dx, this.dy) {
|
|
|
|
assert(dx >= 0);
|
|
|
|
assert(dy >= 0);
|
|
|
|
}
|
|
|
|
|
2023-09-21 23:11:34 +00:00
|
|
|
Size get size => Size(dx, dy);
|
|
|
|
|
2023-09-21 22:37:12 +00:00
|
|
|
bool contains(int x, int y) {
|
|
|
|
return x0 <= x && x < x1 && y0 <= y && y < y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool containsPoint(Offset xy) {
|
|
|
|
return contains(xy.x, xy.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool containsRect(Rect rect) {
|
|
|
|
return x0 <= rect.x0 && y0 <= rect.y0 && rect.x1 <= x1 && rect.y1 <= y1;
|
|
|
|
}
|
2023-09-21 23:11:34 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "@($x0, $y0) $size";
|
|
|
|
}
|
2023-09-21 22:37:12 +00:00
|
|
|
}
|