MutableRectangle<T extends num> 构造函数
- T left,
- T top,
- T width,
- T height
创建一个由 (left, top) 和 (left+width, top+height) 围成的可变矩形。
该矩形包含 x 坐标在 left 到 left + width 之间以及 y 坐标在 top 到 top + height 之间的点,包括两端。
width 和 height 应该是非负的。如果 width 或 height 为负,它们会被强制设置为零。
如果 width 和 height 是零,则“矩形”仅包含单个点 (left, top)。
示例
var rectangle = MutableRectangle(20, 50, 300, 600);
print(rectangle); // Rectangle (20, 50) 300 x 600
print(rectangle.left); // 20
print(rectangle.top); // 50
print(rectangle.right); // 320
print(rectangle.bottom); // 650
// Change rectangle width and height.
rectangle.width = 200;
rectangle.height = 100;
print(rectangle); // Rectangle (20, 50) 200 x 100
print(rectangle.left); // 20
print(rectangle.top); // 50
print(rectangle.right); // 220
print(rectangle.bottom); // 150
旧版: 不鼓励使用 MutableRectangle。想了解更多信息,请查看 MutableRectangle 类的 API 文档。
实现
MutableRectangle(this.left, this.top, T width, T height)
: this._width =
(width < 0) ? _clampToZero<T>(width) : (width + 0 as dynamic),
this._height =
(height < 0) ? _clampToZero<T>(height) : (height + 0 as dynamic);