commonMain.korlibs.math.geom.Circle.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of korma-jvm Show documentation
Show all versions of korma-jvm Show documentation
Mathematic library for Multiplatform Kotlin 1.3
The newest version!
package korlibs.math.geom
import korlibs.math.geom.shape.*
import korlibs.math.geom.vector.*
data class Circle(override val center: Point, val radius: Float) : AbstractShape2D() {
override val lazyVectorPath: VectorPath by lazy { buildVectorPath { circle([email protected], [email protected]) } }
constructor(x: Float, y: Float, radius: Float) : this(Point(x, y), radius)
override val area: Float get() = (PIF * radius * radius)
override val perimeter: Float get() = (PI2F * radius)
override fun distance(p: Point): Float = (p - center).length - radius
override fun normalVectorAt(p: Point): Vector2 = (p - center).normalized
val radiusSquared: Float get() = radius * radius
fun distanceToCenterSquared(p: Point): Float = Point.distanceSquared(p, center)
// @TODO: Check if inside the circle
fun distanceClosestSquared(p: Point): Float = distanceToCenterSquared(p) - radiusSquared
// @TODO: Check if inside the circle
fun distanceFarthestSquared(p: Point): Float = distanceToCenterSquared(p) + radiusSquared
override fun projectedPoint(p: Point): Point = Point.polar(center, Angle.between(center, p), radius)
override fun containsPoint(p: Point): Boolean = (p - center).length <= radius
}