Add builder for pixelMap to scheme
This commit is contained in:
parent
3b43446f82
commit
4658418517
@ -12,11 +12,6 @@ import center.sciprog.maps.coordinates.Gmc
|
|||||||
import center.sciprog.maps.coordinates.GmcCurve
|
import center.sciprog.maps.coordinates.GmcCurve
|
||||||
import center.sciprog.maps.features.*
|
import center.sciprog.maps.features.*
|
||||||
import space.kscience.kmath.geometry.Angle
|
import space.kscience.kmath.geometry.Angle
|
||||||
import space.kscience.kmath.nd.BufferND
|
|
||||||
import space.kscience.kmath.nd.ShapeND
|
|
||||||
import space.kscience.kmath.nd.Strides
|
|
||||||
import space.kscience.kmath.nd.as2D
|
|
||||||
import space.kscience.kmath.structures.Buffer
|
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
|
||||||
|
|
||||||
@ -122,35 +117,27 @@ public fun FeatureGroup<Gmc>.text(
|
|||||||
TextFeature(space, coordinatesOf(position), text, fontConfig = font)
|
TextFeature(space, coordinatesOf(position), text, fontConfig = font)
|
||||||
)
|
)
|
||||||
|
|
||||||
public fun <T> BufferND(shape: ShapeND, initializer: (IntArray) -> T): BufferND<T> {
|
|
||||||
val strides = Strides(shape)
|
|
||||||
return BufferND(strides, Buffer.boxing(strides.linearSize) { initializer(strides.index(it)) })
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun FeatureGroup<Gmc>.pixelMap(
|
public fun FeatureGroup<Gmc>.pixelMap(
|
||||||
rectangle: Rectangle<Gmc>,
|
rectangle: Rectangle<Gmc>,
|
||||||
latitudeDelta: Angle,
|
latitudeDelta: Angle,
|
||||||
longitudeDelta: Angle,
|
longitudeDelta: Angle,
|
||||||
id: String? = null,
|
id: String? = null,
|
||||||
builder: (Gmc) -> Color?,
|
builder: (Gmc) -> Color?,
|
||||||
): FeatureRef<Gmc, PixelMapFeature<Gmc>> {
|
): FeatureRef<Gmc, PixelMapFeature<Gmc>> = feature(
|
||||||
val shape = ShapeND(
|
|
||||||
ceil(rectangle.longitudeDelta / latitudeDelta).toInt(),
|
|
||||||
ceil(rectangle.latitudeDelta / longitudeDelta).toInt()
|
|
||||||
)
|
|
||||||
|
|
||||||
return feature(
|
|
||||||
id,
|
id,
|
||||||
PixelMapFeature(
|
PixelMapFeature(
|
||||||
space,
|
space,
|
||||||
rectangle,
|
rectangle,
|
||||||
BufferND(shape) { (i, j) ->
|
Structure2D(
|
||||||
|
ceil(rectangle.longitudeDelta / latitudeDelta).toInt(),
|
||||||
|
ceil(rectangle.latitudeDelta / longitudeDelta).toInt()
|
||||||
|
|
||||||
|
) { (i, j) ->
|
||||||
val longitude = rectangle.left + longitudeDelta * i
|
val longitude = rectangle.left + longitudeDelta * i
|
||||||
val latitude = rectangle.bottom + latitudeDelta * j
|
val latitude = rectangle.bottom + latitudeDelta * j
|
||||||
builder(
|
builder(
|
||||||
Gmc(latitude, longitude)
|
Gmc(latitude, longitude)
|
||||||
)
|
)
|
||||||
}.as2D()
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.runtime.mutableStateMapOf
|
import androidx.compose.runtime.mutableStateMapOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
@ -12,6 +13,8 @@ import androidx.compose.ui.unit.DpSize
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import center.sciprog.attributes.*
|
import center.sciprog.attributes.*
|
||||||
import space.kscience.kmath.geometry.Angle
|
import space.kscience.kmath.geometry.Angle
|
||||||
|
import space.kscience.kmath.nd.*
|
||||||
|
import space.kscience.kmath.structures.Buffer
|
||||||
|
|
||||||
//@JvmInline
|
//@JvmInline
|
||||||
//public value class FeatureId<out F : Feature<*>>(public val id: String)
|
//public value class FeatureId<out F : Feature<*>>(public val id: String)
|
||||||
@ -280,3 +283,23 @@ public fun <T : Any> FeatureGroup<T>.text(
|
|||||||
id,
|
id,
|
||||||
TextFeature(space, position, text, fontConfig = font, attributes = attributes)
|
TextFeature(space, position, text, fontConfig = font, attributes = attributes)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
public fun <T> StructureND(shape: ShapeND, initializer: (IntArray) -> T): StructureND<T> {
|
||||||
|
val strides = Strides(shape)
|
||||||
|
return BufferND(strides, Buffer.boxing(strides.linearSize) { initializer(strides.index(it)) })
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun <T> Structure2D(rows: Int, columns: Int, initializer: (IntArray) -> T): Structure2D<T> {
|
||||||
|
val strides = Strides(ShapeND(rows, columns))
|
||||||
|
return BufferND(strides, Buffer.boxing(strides.linearSize) { initializer(strides.index(it)) }).as2D()
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun <T : Any> FeatureGroup<T>.pixelMap(
|
||||||
|
rectangle: Rectangle<T>,
|
||||||
|
pixelMap: Structure2D<Color?>,
|
||||||
|
attributes: Attributes = Attributes.EMPTY,
|
||||||
|
id: String? = null,
|
||||||
|
): FeatureRef<T, PixelMapFeature<T>> = feature(
|
||||||
|
id,
|
||||||
|
PixelMapFeature(space, rectangle, pixelMap, attributes = attributes)
|
||||||
|
)
|
@ -1,6 +1,7 @@
|
|||||||
package center.sciprog.maps.scheme
|
package center.sciprog.maps.scheme
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
@ -10,6 +11,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import center.sciprog.attributes.Attributes
|
import center.sciprog.attributes.Attributes
|
||||||
import center.sciprog.maps.features.*
|
import center.sciprog.maps.features.*
|
||||||
import space.kscience.kmath.geometry.Angle
|
import space.kscience.kmath.geometry.Angle
|
||||||
|
import kotlin.math.ceil
|
||||||
|
|
||||||
internal fun Pair<Number, Number>.toCoordinates(): XY = XY(first.toFloat(), second.toFloat())
|
internal fun Pair<Number, Number>.toCoordinates(): XY = XY(first.toFloat(), second.toFloat())
|
||||||
|
|
||||||
@ -81,3 +83,29 @@ fun FeatureGroup<XY>.text(
|
|||||||
id: String? = null,
|
id: String? = null,
|
||||||
): FeatureRef<XY, TextFeature<XY>> = text(position.toCoordinates(), text, id = id)
|
): FeatureRef<XY, TextFeature<XY>> = text(position.toCoordinates(), text, id = id)
|
||||||
|
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user