Add arc builders to scheme

This commit is contained in:
Alexander Nozik 2022-09-17 11:44:34 +03:00
parent 409d749054
commit 354cd8c9a2
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
3 changed files with 40 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import space.kscience.gradle.KScienceVersions.JVM_TARGET
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
id("org.jetbrains.compose") id("org.jetbrains.compose")
`maven-publish`
} }
kotlin { kotlin {

View File

@ -11,7 +11,14 @@ data class SchemeCoordinates(val x: Float, val y: Float)
data class SchemeRectangle( data class SchemeRectangle(
val a: SchemeCoordinates, val a: SchemeCoordinates,
val b: SchemeCoordinates, val b: SchemeCoordinates,
) ) {
companion object {
fun square(center: SchemeCoordinates, height: Float, width: Float): SchemeRectangle = SchemeRectangle(
SchemeCoordinates(center.x - width / 2, center.y - height / 2),
SchemeCoordinates(center.x + width / 2, center.y + height / 2),
)
}
}
val SchemeRectangle.top get() = max(a.y, b.y) val SchemeRectangle.top get() = max(a.y, b.y)
val SchemeRectangle.bottom get() = min(a.y, b.y) val SchemeRectangle.bottom get() = min(a.y, b.y)

View File

@ -129,6 +129,37 @@ fun SchemeFeaturesState.line(
id: FeatureId? = null, id: FeatureId? = null,
) = addFeature(id, SchemeLineFeature(aCoordinates.toCoordinates(), bCoordinates.toCoordinates(), scaleRange, color)) ) = addFeature(id, SchemeLineFeature(aCoordinates.toCoordinates(), bCoordinates.toCoordinates(), scaleRange, color))
public fun SchemeFeaturesState.arc(
oval: SchemeRectangle,
startAngle: Float,
arcLength: Float,
scaleRange: FloatRange = defaultScaleRange,
color: Color = Color.Red,
id: FeatureId? = null,
): FeatureId = addFeature(
id,
SchemeArcFeature(oval, startAngle, arcLength, scaleRange, color)
)
public fun SchemeFeaturesState.arc(
center: Pair<Double, Double>,
radius: Float,
startAngle: Float,
arcLength: Float,
scaleRange: FloatRange = defaultScaleRange,
color: Color = Color.Red,
id: FeatureId? = null,
): FeatureId = addFeature(
id,
SchemeArcFeature(
oval = SchemeRectangle.square(center.toCoordinates(), radius, radius),
startAngle = startAngle,
arcLength = arcLength,
scaleRange = scaleRange,
color = color
)
)
fun SchemeFeaturesState.text( fun SchemeFeaturesState.text(
position: SchemeCoordinates, position: SchemeCoordinates,
text: String, text: String,