circleToRect method
圆形和矩形重叠
Implementation
bool circleToRect(DFRect other) {
/// 矩形不重叠,不用判断圆形了
if (!toRect().overlaps(other)) {
return false;
}
/// 排除矩形包含了圆形
if (other.right >= this.center.x + this.radius &&
other.left <= this.center.x - this.radius &&
other.top <= this.center.y - this.radius &&
other.bottom >= this.center.y + this.radius) {
return true;
}
/// 顶点
final points = [
DFPosition(other.left, other.top),
DFPosition(other.right, other.top),
DFPosition(other.right, other.bottom),
DFPosition(other.left, other.bottom),
DFPosition(other.left, other.top),
];
/// print(other.toString());
for (var i = 0; i < points.length - 1; i++) {
final distance = DFUtil.getNearestDistance(points[i], points[i + 1], this.center);
/// print((distance).toString());
if (DFUtil.fixDouble4(distance) <= this.radius) {
return true;
}
}
return false;
}