|
|
|
|
@ -26,6 +26,37 @@ class MathUtils { |
|
|
|
|
|
|
|
|
|
val slope: Float |
|
|
|
|
get() { return (x2 - x1) / (y2 - y1) } |
|
|
|
|
|
|
|
|
|
private fun intersects(line: Line): PointF? { |
|
|
|
|
|
|
|
|
|
val s1_x = this.x2 - this.x1 |
|
|
|
|
val s1_y = this.y2 - this.y1 |
|
|
|
|
val s2_x = line.x2 - line.x1 |
|
|
|
|
val s2_y = line.y2 - line.y1 |
|
|
|
|
|
|
|
|
|
val s = (-s1_y * (this.x1 - line.x1) + s1_x * (this.y1 - line.y1)) / (-s2_x * s1_y + s1_x * s2_y); |
|
|
|
|
val t = ( s2_x * (this.y1 - line.y1) - s2_y * (this.x1 - line.x1)) / (-s2_x * s1_y + s1_x * s2_y); |
|
|
|
|
|
|
|
|
|
return if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { |
|
|
|
|
PointF(this.x1 + (t * s1_x), this.y1 + (t * s1_y)) |
|
|
|
|
} else { |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun intersects(rect: RectF): PointF? { |
|
|
|
|
val p1 = this.intersects(Line(rect.left, rect.top, rect.right, rect.top)) |
|
|
|
|
if (p1 != null) return p1 |
|
|
|
|
val p2 = this.intersects(Line(rect.right, rect.top, rect.right, rect.bottom)) |
|
|
|
|
if (p2 != null) return p2 |
|
|
|
|
val p3 = this.intersects(Line(rect.left, rect.bottom, rect.right, rect.bottom)) |
|
|
|
|
if (p3 != null) return p3 |
|
|
|
|
val p4 = this.intersects(Line(rect.left, rect.top, rect.left, rect.bottom)) |
|
|
|
|
if (p4 != null) return p4 |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class EllipseQuarter(val x1: Float, val y1: Float, val xRadius: Float, val yRadius: Float, val direction: Direction): Path { |
|
|
|
|
|