2022-07-23 11:24:37 +03:00
|
|
|
package center.sciprog.maps.scheme
|
2022-07-23 10:27:58 +03:00
|
|
|
|
|
|
|
import androidx.compose.runtime.Composable
|
2023-03-16 10:10:53 +03:00
|
|
|
import androidx.compose.ui.graphics.Color
|
2022-07-23 10:27:58 +03:00
|
|
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
|
|
|
import androidx.compose.ui.graphics.painter.Painter
|
|
|
|
import androidx.compose.ui.graphics.vector.ImageVector
|
2022-12-25 14:33:31 +03:00
|
|
|
import androidx.compose.ui.unit.Dp
|
2022-07-23 10:27:58 +03:00
|
|
|
import androidx.compose.ui.unit.DpSize
|
|
|
|
import androidx.compose.ui.unit.dp
|
2022-12-25 14:33:31 +03:00
|
|
|
import center.sciprog.maps.features.*
|
2024-02-23 12:11:43 +03:00
|
|
|
import space.kscience.attributes.Attributes
|
2023-02-06 17:19:51 +03:00
|
|
|
import space.kscience.kmath.geometry.Angle
|
2023-03-16 10:10:53 +03:00
|
|
|
import kotlin.math.ceil
|
2022-07-23 10:27:58 +03:00
|
|
|
|
2022-12-25 14:33:31 +03:00
|
|
|
internal fun Pair<Number, Number>.toCoordinates(): XY = XY(first.toFloat(), second.toFloat())
|
2022-07-23 10:27:58 +03:00
|
|
|
|
2023-04-11 17:08:28 +03:00
|
|
|
public fun FeatureGroup<XY>.background(
|
2022-09-17 10:32:28 +03:00
|
|
|
width: Float,
|
|
|
|
height: Float,
|
2022-12-25 14:33:31 +03:00
|
|
|
offset: XY = XY(0f, 0f),
|
|
|
|
id: String? = null,
|
2022-09-17 10:32:28 +03:00
|
|
|
painter: @Composable () -> Painter,
|
2023-02-06 10:37:22 +03:00
|
|
|
): FeatureRef<XY, ScalableImageFeature<XY>> {
|
2022-12-25 14:33:31 +03:00
|
|
|
val box = XYRectangle(
|
2022-07-23 10:27:58 +03:00
|
|
|
offset,
|
2022-12-25 14:33:31 +03:00
|
|
|
XY(width + offset.x, height + offset.y)
|
2022-07-23 10:27:58 +03:00
|
|
|
)
|
2022-12-25 14:51:34 +03:00
|
|
|
return feature(
|
|
|
|
id,
|
2023-01-01 09:10:01 +03:00
|
|
|
ScalableImageFeature(
|
|
|
|
space,
|
|
|
|
box,
|
|
|
|
painter = painter,
|
|
|
|
attributes = Attributes(ZAttribute, -100f)
|
|
|
|
)
|
2022-12-25 14:51:34 +03:00
|
|
|
)
|
2022-07-23 10:27:58 +03:00
|
|
|
}
|
|
|
|
|
2023-04-11 17:08:28 +03:00
|
|
|
public fun FeatureGroup<XY>.circle(
|
2022-07-23 10:27:58 +03:00
|
|
|
centerCoordinates: Pair<Number, Number>,
|
2022-12-25 14:33:31 +03:00
|
|
|
size: Dp = 5.dp,
|
|
|
|
id: String? = null,
|
2023-09-10 13:12:45 +03:00
|
|
|
): FeatureRef<XY, CircleFeature<XY>> = circle(centerCoordinates.toCoordinates(), size, id = id)
|
2022-07-23 10:27:58 +03:00
|
|
|
|
2023-04-11 17:08:28 +03:00
|
|
|
public fun FeatureGroup<XY>.draw(
|
2022-07-23 10:27:58 +03:00
|
|
|
position: Pair<Number, Number>,
|
2022-12-25 14:33:31 +03:00
|
|
|
id: String? = null,
|
|
|
|
draw: DrawScope.() -> Unit,
|
2023-02-06 10:37:22 +03:00
|
|
|
): FeatureRef<XY, DrawFeature<XY>> = draw(position.toCoordinates(), id = id, draw = draw)
|
2022-07-23 10:27:58 +03:00
|
|
|
|
2023-04-11 17:08:28 +03:00
|
|
|
public fun FeatureGroup<XY>.line(
|
2022-07-23 10:27:58 +03:00
|
|
|
aCoordinates: Pair<Number, Number>,
|
|
|
|
bCoordinates: Pair<Number, Number>,
|
2022-12-25 14:33:31 +03:00
|
|
|
id: String? = null,
|
2023-02-13 16:49:36 +03:00
|
|
|
): FeatureRef<XY, LineFeature<XY>> = line(aCoordinates.toCoordinates(), bCoordinates.toCoordinates(), id = id)
|
2022-07-23 10:27:58 +03:00
|
|
|
|
2022-09-17 11:44:34 +03:00
|
|
|
|
2023-01-02 14:08:20 +03:00
|
|
|
public fun FeatureGroup<XY>.arc(
|
2022-09-17 11:44:34 +03:00
|
|
|
center: Pair<Double, Double>,
|
|
|
|
radius: Float,
|
2023-02-06 17:19:51 +03:00
|
|
|
startAngle: Angle,
|
|
|
|
arcLength: Angle,
|
2022-12-25 14:33:31 +03:00
|
|
|
id: String? = null,
|
2023-02-06 10:37:22 +03:00
|
|
|
): FeatureRef<XY, ArcFeature<XY>> = arc(
|
2023-09-10 13:12:45 +03:00
|
|
|
oval = XYCoordinateSpace.Rectangle(center.toCoordinates(), 2 * radius, 2 * radius),
|
2022-12-25 14:33:31 +03:00
|
|
|
startAngle = startAngle,
|
|
|
|
arcLength = arcLength,
|
2023-01-01 09:10:01 +03:00
|
|
|
id = id
|
2022-09-17 11:44:34 +03:00
|
|
|
)
|
|
|
|
|
2023-04-11 17:08:28 +03:00
|
|
|
public fun FeatureGroup<XY>.image(
|
2022-12-25 14:33:31 +03:00
|
|
|
position: Pair<Number, Number>,
|
|
|
|
image: ImageVector,
|
|
|
|
size: DpSize = DpSize(image.defaultWidth, image.defaultHeight),
|
|
|
|
id: String? = null,
|
2023-04-11 17:08:28 +03:00
|
|
|
): FeatureRef<XY, VectorIconFeature<XY>> =
|
|
|
|
icon(position.toCoordinates(), image, size = size, id = id)
|
2022-07-23 10:27:58 +03:00
|
|
|
|
2023-04-11 17:08:28 +03:00
|
|
|
public fun FeatureGroup<XY>.text(
|
2022-07-23 10:27:58 +03:00
|
|
|
position: Pair<Number, Number>,
|
|
|
|
text: String,
|
2022-12-25 14:33:31 +03:00
|
|
|
id: String? = null,
|
2023-02-06 10:37:22 +03:00
|
|
|
): FeatureRef<XY, TextFeature<XY>> = text(position.toCoordinates(), text, id = id)
|
2022-07-23 10:27:58 +03:00
|
|
|
|
2023-03-16 10:10:53 +03:00
|
|
|
public fun FeatureGroup<XY>.pixelMap(
|
|
|
|
rectangle: Rectangle<XY>,
|
|
|
|
xSize: Float,
|
|
|
|
ySize: Float,
|
|
|
|
id: String? = null,
|
|
|
|
builder: (XY) -> Color?,
|
|
|
|
): FeatureRef<XY, PixelMapFeature<XY>> = feature(
|
|
|
|
id,
|
|
|
|
PixelMapFeature(
|
|
|
|
space,
|
|
|
|
rectangle,
|
|
|
|
Structure2D(
|
|
|
|
ceil(rectangle.width / xSize).toInt(),
|
|
|
|
ceil(rectangle.height / ySize).toInt()
|
|
|
|
|
|
|
|
) { (i, j) ->
|
|
|
|
val longitude = rectangle.left + xSize * i
|
|
|
|
val latitude = rectangle.bottom + ySize * j
|
|
|
|
builder(
|
|
|
|
XY(latitude, longitude)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-09-10 13:12:45 +03:00
|
|
|
public fun FeatureGroup<XY>.rectanglePolygon(
|
|
|
|
left: Number, right: Number,
|
|
|
|
bottom: Number, top: Number,
|
|
|
|
attributes: Attributes = Attributes.EMPTY,
|
|
|
|
id: String? = null,
|
|
|
|
): FeatureRef<XY, PolygonFeature<XY>> = polygon(
|
|
|
|
listOf(
|
|
|
|
XY(left.toFloat(), top.toFloat()),
|
|
|
|
XY(right.toFloat(), top.toFloat()),
|
|
|
|
XY(right.toFloat(), bottom.toFloat()),
|
|
|
|
XY(left.toFloat(), bottom.toFloat())
|
|
|
|
),
|
|
|
|
attributes, id
|
|
|
|
)
|
|
|
|
|
|
|
|
public fun FeatureGroup<XY>.rectanglePolygon(
|
|
|
|
rectangle: Rectangle<XY>,
|
|
|
|
attributes: Attributes = Attributes.EMPTY,
|
|
|
|
id: String? = null,
|
|
|
|
): FeatureRef<XY, PolygonFeature<XY>> = polygon(
|
|
|
|
listOf(
|
|
|
|
XY(rectangle.left, rectangle.top),
|
|
|
|
XY(rectangle.right, rectangle.top),
|
|
|
|
XY(rectangle.right, rectangle.bottom),
|
|
|
|
XY(rectangle.left, rectangle.bottom)
|
|
|
|
),
|
|
|
|
attributes, id
|
|
|
|
)
|
|
|
|
|
2023-03-16 10:10:53 +03:00
|
|
|
|