Metaregions 1
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
// and I strongly prefer half-open bounds
|
||||
//
|
||||
// So: Here's a reimplementation of the geometry I need
|
||||
import 'package:dartterm/skreek.dart';
|
||||
|
||||
class Size {
|
||||
final int dx;
|
||||
final int dy;
|
||||
@ -10,6 +12,11 @@ class Size {
|
||||
assert(dx >= 0);
|
||||
assert(dy >= 0);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "$dx x $dy";
|
||||
}
|
||||
}
|
||||
|
||||
class Offset {
|
||||
@ -17,6 +24,11 @@ class Offset {
|
||||
final int y;
|
||||
|
||||
const Offset(this.x, this.y);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "@($x, $y)";
|
||||
}
|
||||
}
|
||||
|
||||
class Rect {
|
||||
@ -33,6 +45,8 @@ class Rect {
|
||||
assert(dy >= 0);
|
||||
}
|
||||
|
||||
Size get size => Size(dx, dy);
|
||||
|
||||
bool contains(int x, int y) {
|
||||
return x0 <= x && x < x1 && y0 <= y && y < y1;
|
||||
}
|
||||
@ -44,4 +58,9 @@ class Rect {
|
||||
bool containsRect(Rect rect) {
|
||||
return x0 <= rect.x0 && y0 <= rect.y0 && rect.x1 <= x1 && rect.y1 <= y1;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "@($x0, $y0) $size";
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ import 'dart:math' as math;
|
||||
import 'package:dartterm/algorithms/geometry.dart' as geo;
|
||||
|
||||
class Region {
|
||||
final math.Rectangle<int> rect;
|
||||
final geo.Rect rect;
|
||||
final Set<(int, int)> points;
|
||||
|
||||
bool get isRectangle => points.length == rect.width * rect.height;
|
||||
bool get isRectangle => points.length == rect.dx * rect.dy;
|
||||
|
||||
Region(this.rect, this.points);
|
||||
|
||||
@ -16,8 +16,7 @@ class Region {
|
||||
int yMin = s.map<int>((xy) => xy.$2).reduce(math.min);
|
||||
int xMax = s.map<int>((xy) => xy.$1).reduce(math.max);
|
||||
int yMax = s.map<int>((xy) => xy.$2).reduce(math.max);
|
||||
var rect = math.Rectangle.fromPoints(
|
||||
math.Point(xMin, yMin), math.Point(xMax + 1, yMax + 1));
|
||||
var rect = geo.Rect(xMin, yMin, xMax - xMin + 1, yMax - yMin + 1);
|
||||
return Region(rect, s);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user