diff --git a/geojson/build.gradle.kts b/geojson/build.gradle.kts index de96e1d1..d06d907d 100644 --- a/geojson/build.gradle.kts +++ b/geojson/build.gradle.kts @@ -10,6 +10,8 @@ plugins { } kotlin { + explicitApi() + jvm { compilations.create("bench") } diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/BoundingBox.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/BoundingBox.kt index 4973367c..500d3e95 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/BoundingBox.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/BoundingBox.kt @@ -24,20 +24,20 @@ import kotlinx.serialization.Serializable */ @Serializable(with = BoundingBoxSerializer::class) @Suppress("MagicNumber") -class BoundingBox constructor(val coordinates: DoubleArray) { +public class BoundingBox constructor(public val coordinates: DoubleArray) { init { require(coordinates.size == 4 || coordinates.size == 6) { "Bounding Box coordinates must either have 4 or 6 values" } } - constructor(west: Double, south: Double, east: Double, north: Double) : this( + public constructor(west: Double, south: Double, east: Double, north: Double) : this( doubleArrayOf(west, south, east, north) ) - constructor(coordinates: List) : this(coordinates.toDoubleArray()) + public constructor(coordinates: List) : this(coordinates.toDoubleArray()) - constructor( + public constructor( west: Double, south: Double, minAltitude: Double, @@ -46,27 +46,27 @@ class BoundingBox constructor(val coordinates: DoubleArray) { maxAltitude: Double ) : this(doubleArrayOf(west, south, minAltitude, east, north, maxAltitude)) - constructor(southwest: Position, northeast: Position) : this( + public constructor(southwest: Position, northeast: Position) : this( when (southwest.hasAltitude && northeast.hasAltitude) { true -> southwest.coordinates + northeast.coordinates false -> doubleArrayOf(southwest.longitude, southwest.latitude, northeast.longitude, northeast.latitude) } ) - val southwest: Position + public val southwest: Position get() = when (hasAltitude) { true -> Position(coordinates[0], coordinates[1], coordinates[2]) false -> Position(coordinates[0], coordinates[1]) } - val northeast: Position + public val northeast: Position get() = when (hasAltitude) { true -> Position(coordinates[3], coordinates[4], coordinates[5]) false -> Position(coordinates[2], coordinates[3]) } - operator fun component1(): Position = southwest - operator fun component2(): Position = northeast + public operator fun component1(): Position = southwest + public operator fun component2(): Position = northeast override fun equals(other: Any?): Boolean { if (this === other) return true @@ -87,9 +87,9 @@ class BoundingBox constructor(val coordinates: DoubleArray) { return "BoundingBox(southwest=$southwest, northeast=$northeast)" } - fun json(): String = coordinates.jsonJoin() + public fun json(): String = coordinates.jsonJoin() } @Suppress("MagicNumber") -val BoundingBox.hasAltitude: Boolean +public val BoundingBox.hasAltitude: Boolean get() = coordinates.size == 6 diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/ExperimentalGeoJsonApi.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/ExperimentalGeoJsonApi.kt index 53aa5f54..d3740608 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/ExperimentalGeoJsonApi.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/ExperimentalGeoJsonApi.kt @@ -3,4 +3,4 @@ package io.github.dellisd.spatialk.geojson @RequiresOptIn(message = "This API is experimental. It may be changed in the future without notice.") @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -annotation class ExperimentalGeoJsonApi +public annotation class ExperimentalGeoJsonApi diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Feature.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Feature.kt index ea22bdfb..1635c7f6 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Feature.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Feature.kt @@ -32,40 +32,40 @@ import kotlin.jvm.JvmStatic */ @Suppress("TooManyFunctions") @Serializable(with = FeatureSerializer::class) -class Feature( - val geometry: Geometry?, +public class Feature( + public val geometry: Geometry?, properties: Map = emptyMap(), - val id: String? = null, + public val id: String? = null, override val bbox: BoundingBox? = null ) : GeoJson { private val _properties: MutableMap = properties.toMutableMap() - val properties: Map get() = _properties + public val properties: Map get() = _properties - fun setStringProperty(key: String, value: String?) { + public fun setStringProperty(key: String, value: String?) { _properties[key] = JsonPrimitive(value) } - fun setNumberProperty(key: String, value: Number?) { + public fun setNumberProperty(key: String, value: Number?) { _properties[key] = JsonPrimitive(value) } - fun setBooleanProperty(key: String, value: Boolean?) { + public fun setBooleanProperty(key: String, value: Boolean?) { _properties[key] = JsonPrimitive(value) } - fun setJsonProperty(key: String, value: JsonElement) { + public fun setJsonProperty(key: String, value: JsonElement) { _properties[key] = value } - fun getStringProperty(key: String): String? = properties[key]?.jsonPrimitive?.content + public fun getStringProperty(key: String): String? = properties[key]?.jsonPrimitive?.content - fun getNumberProperty(key: String): Number? = properties[key]?.jsonPrimitive?.double + public fun getNumberProperty(key: String): Number? = properties[key]?.jsonPrimitive?.double - fun getBooleanProperty(key: String): Boolean? = properties[key]?.jsonPrimitive?.boolean + public fun getBooleanProperty(key: String): Boolean? = properties[key]?.jsonPrimitive?.boolean - fun getJsonProperty(key: String): JsonElement? = properties[key] + public fun getJsonProperty(key: String): JsonElement? = properties[key] - fun removeProperty(key: String): Any? = _properties.remove(key) + public fun removeProperty(key: String): Any? = _properties.remove(key) /** * Gets the value of the property with the given [key]. @@ -74,7 +74,7 @@ class Feature( * @return The value of the property cast to [T]?, or null if the key had no value. */ @JvmName("getPropertyCast") - inline fun getProperty(key: String) = properties[key] as T? + public inline fun getProperty(key: String): T? = properties[key] as T? override fun equals(other: Any?): Boolean { if (this === other) return true @@ -98,10 +98,10 @@ class Feature( return result } - operator fun component1() = geometry - operator fun component2() = properties - operator fun component3() = id - operator fun component4() = bbox + public operator fun component1(): Geometry? = geometry + public operator fun component2(): Map = properties + public operator fun component3(): String? = id + public operator fun component4(): BoundingBox? = bbox override fun toString(): String = json() @@ -115,16 +115,16 @@ class Feature( ) }}""" - fun copy( + public fun copy( geometry: Geometry? = this.geometry, properties: Map = this.properties, id: String? = this.id, bbox: BoundingBox? = this.bbox ): Feature = Feature(geometry, properties, id, bbox) - companion object { + public companion object { @JvmStatic - fun fromJson(json: String): Feature = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) + public fun fromJson(json: String): Feature = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) @JvmStatic public fun fromJsonOrNull(json: String): Feature? = try { diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/FeatureCollection.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/FeatureCollection.kt index 6fb43fa3..9cf2f536 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/FeatureCollection.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/FeatureCollection.kt @@ -22,12 +22,12 @@ import kotlin.jvm.JvmStatic * @property features The collection of [Feature] objects stored in this collection */ @Serializable(with = FeatureCollectionSerializer::class) -class FeatureCollection( - val features: List = emptyList(), +public class FeatureCollection( + public val features: List = emptyList(), override val bbox: BoundingBox? = null ) : Collection by features, GeoJson { - constructor(vararg features: Feature, bbox: BoundingBox? = null) : this(features.toMutableList(), bbox) + public constructor(vararg features: Feature, bbox: BoundingBox? = null) : this(features.toMutableList(), bbox) override fun equals(other: Any?): Boolean { if (this === other) return true @@ -52,10 +52,10 @@ class FeatureCollection( override fun json(): String = """{"type":"FeatureCollection",${bbox.jsonProp()}"features":${features.jsonJoin { it.json() }}}""" - operator fun component1(): List = features - operator fun component2(): BoundingBox? = bbox + public operator fun component1(): List = features + public operator fun component2(): BoundingBox? = bbox - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): FeatureCollection = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/GeoJson.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/GeoJson.kt index cb1acb43..af73b8b3 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/GeoJson.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/GeoJson.kt @@ -5,12 +5,12 @@ package io.github.dellisd.spatialk.geojson * * @property bbox An optional bounding box used to represent the limits of the object's geometry. */ -interface GeoJson { - val bbox: BoundingBox? +public interface GeoJson { + public val bbox: BoundingBox? /** * Gets a JSON representation of this object. * @return JSON representation */ - fun json(): String + public fun json(): String } diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Geometry.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Geometry.kt index d6ce39b7..a8de07ca 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Geometry.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Geometry.kt @@ -8,12 +8,12 @@ import kotlinx.serialization.json.jsonPrimitive import kotlin.jvm.JvmStatic @Serializable(with = GeometrySerializer::class) -sealed class Geometry protected constructor() : GeoJson { +public sealed class Geometry protected constructor() : GeoJson { abstract override val bbox: BoundingBox? override fun toString(): String = json() - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): Geometry = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/GeometryCollection.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/GeometryCollection.kt index 4af24319..af34ca68 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/GeometryCollection.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/GeometryCollection.kt @@ -15,12 +15,12 @@ import kotlin.jvm.JvmStatic @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(with = GeometrySerializer::class) -class GeometryCollection @JvmOverloads constructor( - val geometries: List, +public class GeometryCollection @JvmOverloads constructor( + public val geometries: List, override val bbox: BoundingBox? = null ) : Geometry(), Collection by geometries { @JvmOverloads - constructor(vararg geometries: Geometry, bbox: BoundingBox? = null) : this(geometries.toList(), bbox) + public constructor(vararg geometries: Geometry, bbox: BoundingBox? = null) : this(geometries.toList(), bbox) override fun equals(other: Any?): Boolean { if (this === other) return true @@ -43,7 +43,7 @@ class GeometryCollection @JvmOverloads constructor( override fun json(): String = """{"type":"GeometryCollection",${bbox.jsonProp()}"geometries":${geometries.jsonJoin { it.json() }}}""" - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): GeometryCollection = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/LineString.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/LineString.kt index a4380119..5c783360 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/LineString.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/LineString.kt @@ -15,15 +15,15 @@ import kotlin.jvm.JvmStatic @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(with = GeometrySerializer::class) -class LineString @JvmOverloads constructor( - val coordinates: List, +public class LineString @JvmOverloads constructor( + public val coordinates: List, override val bbox: BoundingBox? = null ) : Geometry() { @JvmOverloads - constructor(vararg coordinates: Position, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) + public constructor(vararg coordinates: Position, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) @JvmOverloads - constructor( + public constructor( coordinates: Array, bbox: BoundingBox? = null ) : this(coordinates.map(::Position), bbox) @@ -53,7 +53,7 @@ class LineString @JvmOverloads constructor( override fun json(): String = """{"type":"LineString",${bbox.jsonProp()}"coordinates":${coordinates.jsonJoin(transform = Position::json)}}""" - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): LineString = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiLineString.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiLineString.kt index e88ce4f0..6107e700 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiLineString.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiLineString.kt @@ -15,15 +15,15 @@ import kotlin.jvm.JvmStatic @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(with = GeometrySerializer::class) -class MultiLineString @JvmOverloads constructor( - val coordinates: List>, +public class MultiLineString @JvmOverloads constructor( + public val coordinates: List>, override val bbox: BoundingBox? = null ) : Geometry() { @JvmOverloads - constructor(vararg coordinates: List, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) + public constructor(vararg coordinates: List, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) @JvmOverloads - constructor( + public constructor( coordinates: Array>, bbox: BoundingBox? = null ) : this(coordinates.map { it.map(::Position) }, bbox) @@ -59,7 +59,7 @@ class MultiLineString @JvmOverloads constructor( } }}""" - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): MultiLineString = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiPoint.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiPoint.kt index e02e6305..08b2c698 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiPoint.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiPoint.kt @@ -15,15 +15,15 @@ import kotlin.jvm.JvmStatic @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(with = GeometrySerializer::class) -class MultiPoint @JvmOverloads constructor( - val coordinates: List, +public class MultiPoint @JvmOverloads constructor( + public val coordinates: List, override val bbox: BoundingBox? = null ) : Geometry() { @JvmOverloads - constructor(vararg coordinates: Position, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) + public constructor(vararg coordinates: Position, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) @JvmOverloads - constructor( + public constructor( coordinates: Array, bbox: BoundingBox? = null ) : this(coordinates.map(::Position), bbox) @@ -49,7 +49,7 @@ class MultiPoint @JvmOverloads constructor( override fun json(): String = """{"type":"MultiPoint",${bbox.jsonProp()}"coordinates":${coordinates.jsonJoin(transform = Position::json)}}""" - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): MultiPoint = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiPolygon.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiPolygon.kt index 957dc5b6..f1b85456 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiPolygon.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/MultiPolygon.kt @@ -15,15 +15,15 @@ import kotlin.jvm.JvmStatic @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(with = GeometrySerializer::class) -class MultiPolygon @JvmOverloads constructor( - val coordinates: List>>, +public class MultiPolygon @JvmOverloads constructor( + public val coordinates: List>>, override val bbox: BoundingBox? = null ) : Geometry() { @JvmOverloads - constructor(vararg coordinates: List>, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) + public constructor(vararg coordinates: List>, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) @JvmOverloads - constructor( + public constructor( coordinates: Array>>, bbox: BoundingBox? = null ) : this(coordinates.map { ring -> ring.map { it.map(::Position) } }, bbox) @@ -55,7 +55,7 @@ class MultiPolygon @JvmOverloads constructor( } }}""" - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): MultiPolygon = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Point.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Point.kt index ad86d22e..7e94e2fa 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Point.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Point.kt @@ -14,9 +14,9 @@ import kotlin.jvm.JvmStatic @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(with = GeometrySerializer::class) -class Point @JvmOverloads constructor(val coordinates: Position, override val bbox: BoundingBox? = null) : Geometry() { +public class Point @JvmOverloads constructor(public val coordinates: Position, override val bbox: BoundingBox? = null) : Geometry() { @JvmOverloads - constructor(coordinates: DoubleArray, bbox: BoundingBox? = null) : this(Position(coordinates), bbox) + public constructor(coordinates: DoubleArray, bbox: BoundingBox? = null) : this(Position(coordinates), bbox) override fun equals(other: Any?): Boolean { if (this === other) return true @@ -38,7 +38,7 @@ class Point @JvmOverloads constructor(val coordinates: Position, override val bb override fun json(): String = """{"type":"Point",${bbox.jsonProp()}"coordinates":${coordinates.json()}}""" - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): Point = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Polygon.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Polygon.kt index 1cb50819..2d1b90d9 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Polygon.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Polygon.kt @@ -15,15 +15,15 @@ import kotlin.jvm.JvmStatic @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(with = GeometrySerializer::class) -class Polygon @JvmOverloads constructor( - val coordinates: List>, +public class Polygon @JvmOverloads constructor( + public val coordinates: List>, override val bbox: BoundingBox? = null ) : Geometry() { @JvmOverloads - constructor(vararg coordinates: List, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) + public constructor(vararg coordinates: List, bbox: BoundingBox? = null) : this(coordinates.toList(), bbox) @JvmOverloads - constructor( + public constructor( coordinates: Array>, bbox: BoundingBox? = null ) : this(coordinates.map { it.map(::Position) }, bbox) @@ -51,7 +51,7 @@ class Polygon @JvmOverloads constructor( coordinates.jsonJoin { it.jsonJoin(transform = Position::json) } }}""" - companion object { + public companion object { @JvmStatic public fun fromJson(json: String): Polygon = fromJson(Json.decodeFromString(JsonObject.serializer(), json)) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Position.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Position.kt index 852e942a..d42eae88 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Position.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/Position.kt @@ -33,13 +33,13 @@ import kotlin.jvm.JvmSynthetic * @property altitude Optionally, an altitude or elevation for this position */ @Serializable(with = PositionSerializer::class) -class Position(val coordinates: DoubleArray) { +public class Position(public val coordinates: DoubleArray) { init { require(coordinates.size >= 2) { "At least two coordinates must be provided" } } - constructor(longitude: Double, latitude: Double) : this(doubleArrayOf(longitude, latitude)) - constructor(longitude: Double, latitude: Double, altitude: Double) : this( + public constructor(longitude: Double, latitude: Double) : this(doubleArrayOf(longitude, latitude)) + public constructor(longitude: Double, latitude: Double, altitude: Double) : this( doubleArrayOf( longitude, latitude, @@ -47,18 +47,18 @@ class Position(val coordinates: DoubleArray) { ) ) - constructor(longitude: Double, latitude: Double, altitude: Double?) : this( + public constructor(longitude: Double, latitude: Double, altitude: Double?) : this( when (altitude) { null -> doubleArrayOf(longitude, latitude) else -> doubleArrayOf(longitude, latitude, altitude) } ) - val longitude: Double + public val longitude: Double get() = coordinates[0] - val latitude: Double + public val latitude: Double get() = coordinates[1] - val altitude: Double? + public val altitude: Double? get() = coordinates.getOrNull(2) /** @@ -66,21 +66,21 @@ class Position(val coordinates: DoubleArray) { * @return [longitude] */ @JvmSynthetic - operator fun component1(): Double = longitude + public operator fun component1(): Double = longitude /** * Component function for getting the [latitude] * @return [latitude] */ @JvmSynthetic - operator fun component2(): Double = latitude + public operator fun component2(): Double = latitude /** * Component function for getting the [altitude] * @return [altitude] */ @JvmSynthetic - operator fun component3(): Double? = altitude + public operator fun component3(): Double? = altitude override fun equals(other: Any?): Boolean { if (this === other) return true @@ -101,8 +101,8 @@ class Position(val coordinates: DoubleArray) { return "LngLat(longitude=$longitude, latitude=$latitude, altitude=$altitude)" } - fun json(): String = coordinates.jsonJoin() + public fun json(): String = coordinates.jsonJoin() } @Suppress("MagicNumber") -val Position.hasAltitude: Boolean get() = coordinates.size == 3 +public val Position.hasAltitude: Boolean get() = coordinates.size == 3 diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/FeatureCollectionDsl.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/FeatureCollectionDsl.kt index 970f0e65..8d142b89 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/FeatureCollectionDsl.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/FeatureCollectionDsl.kt @@ -9,18 +9,18 @@ import io.github.dellisd.spatialk.geojson.Geometry import kotlin.jvm.JvmName @GeoJsonDsl -class FeatureCollectionDsl( +public class FeatureCollectionDsl( private val features: MutableList = mutableListOf(), - var bbox: BoundingBox? = null + public var bbox: BoundingBox? = null ) { - operator fun Feature.unaryPlus() { + public operator fun Feature.unaryPlus() { features.add(this) } - fun create(): FeatureCollection = + public fun create(): FeatureCollection = FeatureCollection(features, bbox) - fun feature( + public fun feature( geometry: Geometry? = null, id: String? = null, bbox: BoundingBox? = null, @@ -31,5 +31,5 @@ class FeatureCollectionDsl( } @GeoJsonDsl -inline fun featureCollection(block: FeatureCollectionDsl.() -> Unit) = FeatureCollectionDsl() +public inline fun featureCollection(block: FeatureCollectionDsl.() -> Unit): FeatureCollection = FeatureCollectionDsl() .apply(block).create() diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/FeatureDsl.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/FeatureDsl.kt index a4af667e..15915520 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/FeatureDsl.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/FeatureDsl.kt @@ -11,32 +11,32 @@ import kotlinx.serialization.json.JsonPrimitive import kotlin.jvm.JvmName @GeoJsonDsl -class PropertiesBuilder { +public class PropertiesBuilder { private val properties = mutableMapOf() - fun put(key: String, value: String?) { + public fun put(key: String, value: String?) { properties[key] = JsonPrimitive(value) } - fun put(key: String, value: Number?) { + public fun put(key: String, value: Number?) { properties[key] = JsonPrimitive(value) } - fun put(key: String, value: Boolean?) { + public fun put(key: String, value: Boolean?) { properties[key] = JsonPrimitive(value) } - fun put(key: String, value: JsonElement) { + public fun put(key: String, value: JsonElement) { properties[key] = value } - fun build(): Map = properties + public fun build(): Map = properties } @GeoJsonDsl -inline fun feature( +public inline fun feature( geometry: Geometry? = null, id: String? = null, bbox: BoundingBox? = null, properties: PropertiesBuilder.() -> Unit = {} -) = Feature(geometry, PropertiesBuilder().apply(properties).build(), id, bbox) +): Feature = Feature(geometry, PropertiesBuilder().apply(properties).build(), id, bbox) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/GeometryDsl.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/GeometryDsl.kt index 9fc9fad9..1e813540 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/GeometryDsl.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/GeometryDsl.kt @@ -15,18 +15,18 @@ import io.github.dellisd.spatialk.geojson.Polygon import kotlin.jvm.JvmName @GeoJsonDsl -abstract class GeometryDsl protected constructor(var bbox: BoundingBox? = null) { - abstract fun create(): T +public abstract class GeometryDsl protected constructor(public var bbox: BoundingBox? = null) { + public abstract fun create(): T } @GeoJsonDsl -class PointDsl(private var coordinates: Position) : GeometryDsl() { +public class PointDsl(private var coordinates: Position) : GeometryDsl() { override fun create(): Point = Point(coordinates, bbox) } @GeoJsonDsl -inline fun point( +public inline fun point( longitude: Double, latitude: Double, altitude: Double? = null, @@ -41,139 +41,139 @@ inline fun point( ).apply(block).create() @GeoJsonDsl -class MultiPointDsl(private val points: MutableList = mutableListOf()) : GeometryDsl() { +public class MultiPointDsl(private val points: MutableList = mutableListOf()) : GeometryDsl() { override fun create(): MultiPoint = MultiPoint(points, bbox) - operator fun Position.unaryPlus() { + public operator fun Position.unaryPlus() { points.add(this) } - operator fun Point.unaryPlus() { + public operator fun Point.unaryPlus() { points.add(this.coordinates) } - fun point(longitude: Double, latitude: Double, altitude: Double? = null) { + public fun point(longitude: Double, latitude: Double, altitude: Double? = null) { points.add(Position(longitude, latitude, altitude)) } } @GeoJsonDsl -inline fun multiPoint(block: MultiPointDsl.() -> Unit): MultiPoint = MultiPointDsl() +public inline fun multiPoint(block: MultiPointDsl.() -> Unit): MultiPoint = MultiPointDsl() .apply(block).create() @GeoJsonDsl -class LineStringDsl(internal val points: MutableList = mutableListOf()) : GeometryDsl() { +public class LineStringDsl(internal val points: MutableList = mutableListOf()) : GeometryDsl() { override fun create(): LineString = LineString(points, bbox) - operator fun Position.unaryPlus() { + public operator fun Position.unaryPlus() { points.add(this) } - operator fun Point.unaryPlus() { + public operator fun Point.unaryPlus() { points.add(this.coordinates) } - fun point(longitude: Double, latitude: Double, altitude: Double? = null) { + public fun point(longitude: Double, latitude: Double, altitude: Double? = null) { points.add(Position(longitude, latitude, altitude)) } } @GeoJsonDsl -inline fun lineString(block: LineStringDsl.() -> Unit) = LineStringDsl() +public inline fun lineString(block: LineStringDsl.() -> Unit): LineString = LineStringDsl() .apply(block).create() @GeoJsonDsl -class MultiLineStringDsl(private val coordinates: MutableList> = mutableListOf()) : +public class MultiLineStringDsl(private val coordinates: MutableList> = mutableListOf()) : GeometryDsl() { override fun create(): MultiLineString = MultiLineString(coordinates) - inline fun lineString(block: LineStringDsl.() -> Unit) { + public inline fun lineString(block: LineStringDsl.() -> Unit) { +LineStringDsl().apply(block).create() } - operator fun LineString.unaryPlus() { + public operator fun LineString.unaryPlus() { this@MultiLineStringDsl.coordinates.add(this.coordinates) } } @GeoJsonDsl -inline fun multiLineString(block: MultiLineStringDsl.() -> Unit) = MultiLineStringDsl() +public inline fun multiLineString(block: MultiLineStringDsl.() -> Unit): MultiLineString = MultiLineStringDsl() .apply(block).create() @GeoJsonDsl -class PolygonDsl(internal val coordinates: MutableList> = mutableListOf()) : GeometryDsl() { +public class PolygonDsl(internal val coordinates: MutableList> = mutableListOf()) : GeometryDsl() { override fun create(): Polygon = Polygon(coordinates, bbox) - inner class RingDsl(internal val points: MutableList = mutableListOf()) { - operator fun Position.unaryPlus() { + public inner class RingDsl(internal val points: MutableList = mutableListOf()) { + public operator fun Position.unaryPlus() { points.add(this) } - operator fun Point.unaryPlus() { + public operator fun Point.unaryPlus() { points.add(this.coordinates) } - inline fun lineString(block: LineStringDsl.() -> Unit) { + public inline fun lineString(block: LineStringDsl.() -> Unit) { +LineStringDsl().apply(block).create() } - fun point(longitude: Double, latitude: Double, altitude: Double? = null) { + public fun point(longitude: Double, latitude: Double, altitude: Double? = null) { points.add(Position(longitude, latitude, altitude)) } - operator fun LineString.unaryPlus() { + public operator fun LineString.unaryPlus() { this@RingDsl.points.addAll(this.coordinates) } - fun complete() { + public fun complete() { points.add(points.first()) } } - fun ring(block: RingDsl.() -> Unit) { + public fun ring(block: RingDsl.() -> Unit) { coordinates.add(RingDsl().apply(block).points) } } @GeoJsonDsl -inline fun polygon(block: PolygonDsl.() -> Unit) = PolygonDsl() +public inline fun polygon(block: PolygonDsl.() -> Unit): Polygon = PolygonDsl() .apply(block).create() @GeoJsonDsl -class MultiPolygonDsl(private val coordinates: MutableList>> = mutableListOf()) : +public class MultiPolygonDsl(private val coordinates: MutableList>> = mutableListOf()) : GeometryDsl() { override fun create(): MultiPolygon = MultiPolygon(coordinates, bbox) - inline fun polygon(block: PolygonDsl.() -> Unit) { + public inline fun polygon(block: PolygonDsl.() -> Unit) { +PolygonDsl().apply(block).create() } - operator fun Polygon.unaryPlus() { + public operator fun Polygon.unaryPlus() { this@MultiPolygonDsl.coordinates.add(this.coordinates) } } @GeoJsonDsl -inline fun multiPolygon(block: MultiPolygonDsl.() -> Unit) = MultiPolygonDsl() +public inline fun multiPolygon(block: MultiPolygonDsl.() -> Unit): MultiPolygon = MultiPolygonDsl() .apply(block).create() @GeoJsonDsl -class GeometryCollectionDsl(private val geometries: MutableList = mutableListOf()) : +public class GeometryCollectionDsl(private val geometries: MutableList = mutableListOf()) : GeometryDsl() { override fun create(): GeometryCollection = GeometryCollection(geometries) - operator fun Geometry.unaryPlus() { + public operator fun Geometry.unaryPlus() { geometries.add(this) } } @GeoJsonDsl -inline fun geometryCollection(block: GeometryCollectionDsl.() -> Unit) = GeometryCollectionDsl() +public inline fun geometryCollection(block: GeometryCollectionDsl.() -> Unit): GeometryCollection = GeometryCollectionDsl() .apply(block).create() diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/Position.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/Position.kt index bdf4bb0e..4d0927ca 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/Position.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/dsl/Position.kt @@ -9,19 +9,19 @@ private val LONGITUDE_RANGE = -180.0..180.0 private val LATITUDE_RANGE = -90.0..90.0 @GeoJsonDsl -fun lngLat(longitude: Double, latitude: Double): Position { +public fun lngLat(longitude: Double, latitude: Double): Position { require(longitude in LONGITUDE_RANGE && latitude in LATITUDE_RANGE) return Position(longitude, latitude) } @GeoJsonDsl -fun lngLat(longitude: Double, latitude: Double, altitude: Double): Position { +public fun lngLat(longitude: Double, latitude: Double, altitude: Double): Position { require(longitude in LONGITUDE_RANGE && latitude in LATITUDE_RANGE) return Position(longitude, latitude, altitude) } @GeoJsonDsl -fun lngLat(longitude: Double, latitude: Double, altitude: Double?): Position { +public fun lngLat(longitude: Double, latitude: Double, altitude: Double?): Position { require(longitude in LONGITUDE_RANGE && latitude in LATITUDE_RANGE) return Position(longitude, latitude, altitude) } diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/BoundingBoxSerializer.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/BoundingBoxSerializer.kt index 1c6c2bc0..2ebf3722 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/BoundingBoxSerializer.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/BoundingBoxSerializer.kt @@ -17,7 +17,7 @@ import kotlinx.serialization.json.double import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonPrimitive -object BoundingBoxSerializer : KSerializer { +public object BoundingBoxSerializer : KSerializer { private const val ARRAY_SIZE_2D = 4 private const val ARRAY_SIZE_3D = 6 diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/FeatureCollectionSerializer.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/FeatureCollectionSerializer.kt index ed7bb5d9..bdbe90e4 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/FeatureCollectionSerializer.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/FeatureCollectionSerializer.kt @@ -12,7 +12,7 @@ import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.put -object FeatureCollectionSerializer : JsonSerializer { +public object FeatureCollectionSerializer : JsonSerializer { override val descriptor: SerialDescriptor = buildClassSerialDescriptor("FeatureCollection") override fun deserialize(input: JsonDecoder): FeatureCollection { diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/FeatureSerializer.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/FeatureSerializer.kt index 8c3a5ba1..058f35ee 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/FeatureSerializer.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/FeatureSerializer.kt @@ -12,7 +12,7 @@ import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.put -object FeatureSerializer : JsonSerializer { +public object FeatureSerializer : JsonSerializer { override val descriptor: SerialDescriptor = buildClassSerialDescriptor("Feature") override fun deserialize(input: JsonDecoder): Feature = Feature.fromJson(input.decodeJsonElement().jsonObject) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/GeometrySerializer.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/GeometrySerializer.kt index ea86c351..8a85f899 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/GeometrySerializer.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/GeometrySerializer.kt @@ -27,7 +27,7 @@ import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.jsonObject @Suppress("LongMethod") -object GeometrySerializer : KSerializer { +public object GeometrySerializer : KSerializer { override val descriptor: SerialDescriptor get() = buildSerialDescriptor("Geometry", PolymorphicKind.SEALED) diff --git a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/PositionSerializer.kt b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/PositionSerializer.kt index 046acdca..d8d01e64 100644 --- a/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/PositionSerializer.kt +++ b/geojson/src/commonMain/kotlin/io/github/dellisd/spatialk/geojson/serialization/PositionSerializer.kt @@ -29,7 +29,7 @@ import kotlinx.serialization.json.jsonPrimitive * * @see Position.Companion.serializer */ -object PositionSerializer : KSerializer { +public object PositionSerializer : KSerializer { override val descriptor: SerialDescriptor get() = buildSerialDescriptor("Position", StructureKind.LIST) diff --git a/turf/build.gradle.kts b/turf/build.gradle.kts index e34882f4..2d2dd033 100644 --- a/turf/build.gradle.kts +++ b/turf/build.gradle.kts @@ -10,6 +10,8 @@ plugins { } kotlin { + explicitApi() + jvm() js { browser { diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Booleans.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Booleans.kt index fe1be0eb..5770d613 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Booleans.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Booleans.kt @@ -21,7 +21,7 @@ import kotlin.jvm.JvmOverloads * @return `true` if the Position is inside the Polygon; `false` if the Position is not inside the Polygon */ @JvmOverloads -fun booleanPointInPolygon(point: Point, polygon: Polygon, ignoreBoundary: Boolean = false): Boolean { +public fun booleanPointInPolygon(point: Point, polygon: Polygon, ignoreBoundary: Boolean = false): Boolean { val bbox = bbox(polygon) // normalize to multipolygon val polys = listOf(polygon.coordinates) @@ -39,7 +39,7 @@ fun booleanPointInPolygon(point: Point, polygon: Polygon, ignoreBoundary: Boolea * @return `true` if the Position is inside the Polygon; `false` if the Position is not inside the Polygon */ @JvmOverloads -fun booleanPointInPolygon(point: Point, polygon: MultiPolygon, ignoreBoundary: Boolean = false): Boolean { +public fun booleanPointInPolygon(point: Point, polygon: MultiPolygon, ignoreBoundary: Boolean = false): Boolean { val bbox = bbox(polygon) val polys = polygon.coordinates return booleanPointInPolygon(point.coordinates, bbox, polys, ignoreBoundary) diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/ExperimentalTurfApi.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/ExperimentalTurfApi.kt index 5d30730d..3de532d0 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/ExperimentalTurfApi.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/ExperimentalTurfApi.kt @@ -3,4 +3,4 @@ package io.github.dellisd.spatialk.turf @RequiresOptIn(message = "This API is experimental. It may be changed in the future without notice.") @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -annotation class ExperimentalTurfApi +public annotation class ExperimentalTurfApi diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Grids.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Grids.kt index 328ecfea..e94bad31 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Grids.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Grids.kt @@ -18,7 +18,7 @@ import kotlin.math.floor * @return a [FeatureCollection] grid of polygons */ @ExperimentalTurfApi -fun squareGrid( +public fun squareGrid( bbox: BoundingBox, cellWidth: Double, cellHeight: Double, @@ -33,8 +33,8 @@ fun squareGrid( val bboxWidth = east - west val cellWidthDeg = convertLength(cellWidth, units, Units.Degrees) - val bboxHeight = north - south; - val cellHeightDeg = convertLength(cellHeight, units, Units.Degrees); + val bboxHeight = north - south + val cellHeightDeg = convertLength(cellHeight, units, Units.Degrees) val columns = floor(abs(bboxWidth) / cellWidthDeg) val rows = floor(abs(bboxHeight) / cellHeightDeg) @@ -58,9 +58,9 @@ fun squareGrid( }.also { featureList.add(Feature(Polygon(it))) } - currentY += cellHeightDeg; + currentY += cellHeightDeg } - currentX += cellWidthDeg; + currentX += cellWidthDeg } return FeatureCollection(featureList) } diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Measurement.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Measurement.kt index 817099a9..1aa264d0 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Measurement.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Measurement.kt @@ -37,7 +37,7 @@ import kotlin.math.sqrt @JvmOverloads @Suppress("MagicNumber") @ExperimentalTurfApi -fun along(line: LineString, distance: Double, units: Units = Units.Kilometers): Position { +public fun along(line: LineString, distance: Double, units: Units = Units.Kilometers): Position { var travelled = 0.0 line.coordinates.forEachIndexed { i, coordinate -> @@ -78,7 +78,7 @@ fun along(line: LineString, distance: Double, units: Units = Units.Kilometers): * @return area in square meters */ @ExperimentalTurfApi -fun area(geometry: Geometry): Double { +public fun area(geometry: Geometry): Double { return when (geometry) { is GeometryCollection -> geometry.geometries.fold(0.0) { acc, geom -> acc + area( @@ -112,7 +112,7 @@ private fun polygonArea(coordinates: List>): Double { return total } -const val AREA_EARTH_RADIUS = 6378137 +public const val AREA_EARTH_RADIUS: Int = 6378137 /** * Calculates the approximate area of the [polygon][coordinates] were it projected onto the earth. @@ -168,7 +168,7 @@ private fun ringArea(coordinates: List): Double { * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(geometry: Geometry): BoundingBox = computeBbox(geometry.coordAll()) +public fun bbox(geometry: Geometry): BoundingBox = computeBbox(geometry.coordAll()) /** * Takes a geometry and calculates the bbox of all input features, and returns a bounding box. @@ -177,7 +177,7 @@ fun bbox(geometry: Geometry): BoundingBox = computeBbox(geometry.coordAll()) * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(geometry: Point) = computeBbox(geometry.coordAll()) +public fun bbox(geometry: Point): BoundingBox = computeBbox(geometry.coordAll()) /** * Takes a geometry and calculates the bbox of all input features, and returns a bounding box. @@ -186,7 +186,7 @@ fun bbox(geometry: Point) = computeBbox(geometry.coordAll()) * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(geometry: MultiPoint) = computeBbox(geometry.coordAll()) +public fun bbox(geometry: MultiPoint): BoundingBox = computeBbox(geometry.coordAll()) /** * Takes a geometry and calculates the bbox of all input features, and returns a bounding box. @@ -195,7 +195,7 @@ fun bbox(geometry: MultiPoint) = computeBbox(geometry.coordAll()) * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(geometry: LineString) = computeBbox(geometry.coordAll()) +public fun bbox(geometry: LineString): BoundingBox = computeBbox(geometry.coordAll()) /** * Takes a geometry and calculates the bbox of all input features, and returns a bounding box. @@ -204,7 +204,7 @@ fun bbox(geometry: LineString) = computeBbox(geometry.coordAll()) * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(geometry: MultiLineString) = computeBbox(geometry.coordAll()) +public fun bbox(geometry: MultiLineString): BoundingBox = computeBbox(geometry.coordAll()) /** * Takes a geometry and calculates the bbox of all input features, and returns a bounding box. @@ -213,7 +213,7 @@ fun bbox(geometry: MultiLineString) = computeBbox(geometry.coordAll()) * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(geometry: Polygon) = computeBbox(geometry.coordAll()) +public fun bbox(geometry: Polygon): BoundingBox = computeBbox(geometry.coordAll()) /** * Takes a geometry and calculates the bbox of all input features, and returns a bounding box. @@ -222,7 +222,7 @@ fun bbox(geometry: Polygon) = computeBbox(geometry.coordAll()) * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(geometry: MultiPolygon) = computeBbox(geometry.coordAll()) +public fun bbox(geometry: MultiPolygon): BoundingBox = computeBbox(geometry.coordAll()) /** * Takes a feature and calculates the bbox of the feature's geometry, and returns a bounding box. @@ -231,7 +231,7 @@ fun bbox(geometry: MultiPolygon) = computeBbox(geometry.coordAll()) * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(feature: Feature): BoundingBox = computeBbox(feature.coordAll() ?: emptyList()) +public fun bbox(feature: Feature): BoundingBox = computeBbox(feature.coordAll() ?: emptyList()) /** * Takes a feature collection and calculates a bbox that covers all features in the collection. @@ -240,10 +240,10 @@ fun bbox(feature: Feature): BoundingBox = computeBbox(feature.coordAll() ?: empt * @return A [BoundingBox] that covers the geometry. */ @ExperimentalTurfApi -fun bbox(featureCollection: FeatureCollection): BoundingBox = computeBbox(featureCollection.coordAll()) +public fun bbox(featureCollection: FeatureCollection): BoundingBox = computeBbox(featureCollection.coordAll()) @Suppress("MagicNumber") -fun computeBbox(coordinates: List): BoundingBox { +public fun computeBbox(coordinates: List): BoundingBox { val result = doubleArrayOf( Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, @@ -277,7 +277,7 @@ fun computeBbox(coordinates: List): BoundingBox { * @return The bounding box as a polygon */ @ExperimentalTurfApi -fun bboxPolygon(bbox: BoundingBox): Polygon { +public fun bboxPolygon(bbox: BoundingBox): Polygon { require(bbox.northeast.altitude == null && bbox.southwest.altitude == null) { "Bounding Box cannot have altitudes" } @@ -295,7 +295,7 @@ fun bboxPolygon(bbox: BoundingBox): Polygon { @JvmSynthetic @ExperimentalTurfApi -fun BoundingBox.toPolygon() = bboxPolygon(this) +public fun BoundingBox.toPolygon(): Polygon = bboxPolygon(this) /** * Takes two positions ([start], [end]) and finds the geographic bearing between them, @@ -308,7 +308,7 @@ fun BoundingBox.toPolygon() = bboxPolygon(this) */ @JvmOverloads @ExperimentalTurfApi -fun bearing(start: Position, end: Position, final: Boolean = false): Double { +public fun bearing(start: Position, end: Position, final: Boolean = false): Double { if (final) return finalBearing(start, end) val lon1 = radians(start.longitude) @@ -344,7 +344,7 @@ internal fun finalBearing(start: Position, end: Position): Double = (bearing( */ @JvmOverloads @ExperimentalTurfApi -fun destination(origin: Position, distance: Double, bearing: Double, units: Units = Units.Kilometers): Position { +public fun destination(origin: Position, distance: Double, bearing: Double, units: Units = Units.Kilometers): Position { val longitude1 = radians(origin.longitude) val latitude1 = radians(origin.latitude) val bearingRad = radians(bearing) @@ -375,7 +375,7 @@ fun destination(origin: Position, distance: Double, bearing: Double, units: Unit */ @JvmOverloads @ExperimentalTurfApi -fun distance(from: Position, to: Position, units: Units = Units.Kilometers): Double { +public fun distance(from: Position, to: Position, units: Units = Units.Kilometers): Double { val dLat = radians(to.latitude - from.latitude) val dLon = radians(to.longitude - from.longitude) val lat1 = radians(from.latitude) @@ -393,7 +393,7 @@ fun distance(from: Position, to: Position, units: Units = Units.Kilometers): Dou * @return The length of the geometry in [units]. */ @ExperimentalTurfApi -fun length(lineString: LineString, units: Units): Double = length(lineString.coordinates, units) +public fun length(lineString: LineString, units: Units): Double = length(lineString.coordinates, units) /** * Calculates the combined length of all [LineString]s from the given [MultiLineString] in the given [Units]. @@ -403,7 +403,7 @@ fun length(lineString: LineString, units: Units): Double = length(lineString.coo * @return The length of the geometry in [units]. */ @ExperimentalTurfApi -fun length(multiLineString: MultiLineString, units: Units): Double = +public fun length(multiLineString: MultiLineString, units: Units): Double = multiLineString.coordinates.fold(0.0) { acc, coords -> acc + length(coords, units) } /** @@ -415,7 +415,7 @@ fun length(multiLineString: MultiLineString, units: Units): Double = * @return The length of the geometry in [units]. */ @ExperimentalTurfApi -fun length(polygon: Polygon, units: Units): Double = +public fun length(polygon: Polygon, units: Units): Double = polygon.coordinates.fold(0.0) { acc, ring -> acc + length(ring, units) } /** @@ -427,7 +427,7 @@ fun length(polygon: Polygon, units: Units): Double = * @return The length of the geometry in [units]. */ @ExperimentalTurfApi -fun length(multiPolygon: MultiPolygon, units: Units): Double = +public fun length(multiPolygon: MultiPolygon, units: Units): Double = multiPolygon.coordinates.fold(0.0) { total, polygon -> total + polygon.fold(0.0) { acc, ring -> acc + length( @@ -457,7 +457,7 @@ private fun length(coords: List, units: Units): Double { * @return A [Position] midway between [point1] and [point2] */ @ExperimentalTurfApi -fun midpoint(point1: Position, point2: Position): Position { +public fun midpoint(point1: Position, point2: Position): Position { val dist = distance(point1, point2) val heading = bearing(point1, point2) @@ -472,7 +472,7 @@ fun midpoint(point1: Position, point2: Position): Position { * @return A [Point] holding the center coordinates */ @ExperimentalTurfApi -fun center(feature: Feature): Point { +public fun center(feature: Feature): Point { val ext = bbox(feature) val x = (ext.southwest.longitude + ext.northeast.longitude) / 2 val y = (ext.southwest.latitude + ext.northeast.latitude) / 2 @@ -485,7 +485,7 @@ fun center(feature: Feature): Point { * @param geometry the [Geometry] to find the center for */ @ExperimentalTurfApi -fun center(geometry: Geometry): Point { +public fun center(geometry: Geometry): Point { return center(Feature(geometry = geometry)) } @@ -502,7 +502,7 @@ fun center(geometry: Geometry): Point { @Suppress("CyclomaticComplexMethod") @Throws(IllegalArgumentException::class) @ExperimentalTurfApi -fun greatCircle(start: Position, end: Position, pointCount: Int = 100, antimeridianOffset: Double = 10.0): Geometry { +public fun greatCircle(start: Position, end: Position, pointCount: Int = 100, antimeridianOffset: Double = 10.0): Geometry { val deltaLongitude = start.longitude - end.longitude val deltaLatitude = start.latitude - end.latitude diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Meta.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Meta.kt index 21665c86..dc0c5f84 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Meta.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Meta.kt @@ -16,7 +16,7 @@ import io.github.dellisd.spatialk.geojson.Position import kotlin.jvm.JvmName @ExperimentalTurfApi -fun Geometry.coordAll(): List = when (this) { +public fun Geometry.coordAll(): List = when (this) { is Point -> this.coordAll() is MultiPoint -> this.coordAll() is LineString -> this.coordAll() @@ -27,33 +27,33 @@ fun Geometry.coordAll(): List = when (this) { } @ExperimentalTurfApi -fun Point.coordAll() = listOf(coordinates) +public fun Point.coordAll(): List = listOf(coordinates) @ExperimentalTurfApi -fun MultiPoint.coordAll() = coordinates +public fun MultiPoint.coordAll(): List = coordinates @ExperimentalTurfApi -fun LineString.coordAll() = coordinates +public fun LineString.coordAll(): List = coordinates @ExperimentalTurfApi -fun MultiLineString.coordAll() = coordinates.reduce { acc, list -> acc + list } +public fun MultiLineString.coordAll(): List = coordinates.reduce { acc, list -> acc + list } @ExperimentalTurfApi -fun Polygon.coordAll() = coordinates.reduce { acc, list -> acc + list } +public fun Polygon.coordAll(): List = coordinates.reduce { acc, list -> acc + list } @ExperimentalTurfApi -fun MultiPolygon.coordAll() = +public fun MultiPolygon.coordAll(): List = coordinates.fold(emptyList()) { acc, list -> list.reduce { innerAcc, innerList -> innerAcc + innerList } + acc } @ExperimentalTurfApi -fun GeometryCollection.coordAll() = +public fun GeometryCollection.coordAll(): List = geometries.fold(emptyList()) { acc, geometry -> acc + geometry.coordAll() } @ExperimentalTurfApi -fun Feature.coordAll() = geometry?.coordAll() +public fun Feature.coordAll(): List? = geometry?.coordAll() @ExperimentalTurfApi -fun FeatureCollection.coordAll() = +public fun FeatureCollection.coordAll(): List = features.fold(emptyList()) { acc, feature -> acc + (feature.coordAll() ?: emptyList()) } diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Miscellaneous.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Miscellaneous.kt index 09bf2254..ac56f5a7 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Miscellaneous.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Miscellaneous.kt @@ -17,7 +17,7 @@ import kotlin.math.max * @throws NotImplementedError if either LineString does not contain exactly two points */ @ExperimentalTurfApi -fun lineIntersect(line1: LineString, line2: LineString): List { +public fun lineIntersect(line1: LineString, line2: LineString): List { if (line1.coordinates.size == 2 && line2.coordinates.size == 2) { val intersect = intersects(line1, line2) return if (intersect != null) listOf(intersect) else emptyList() @@ -78,7 +78,7 @@ internal fun intersects(line1: LineString, line2: LineString): Position? { * @return The sliced subsection of the line */ @ExperimentalTurfApi -fun lineSlice(start: Position, stop: Position, line: LineString): LineString { +public fun lineSlice(start: Position, stop: Position, line: LineString): LineString { val startVertex = nearestPointOnLine(line, start) val stopVertex = nearestPointOnLine(line, stop) @@ -103,7 +103,7 @@ fun lineSlice(start: Position, stop: Position, line: LineString): LineString { * @property index Index of the segment of the line on which [point] lies. */ @ExperimentalTurfApi -data class NearestPointOnLineResult(val point: Position, val distance: Double, val location: Double, val index: Int) +public data class NearestPointOnLineResult(val point: Position, val distance: Double, val location: Double, val index: Int) /** * Finds the closest [Position] along a [LineString] to a given position @@ -113,7 +113,7 @@ data class NearestPointOnLineResult(val point: Position, val distance: Double, v * @return The closest position along the line */ @ExperimentalTurfApi -fun nearestPointOnLine(line: LineString, point: Position, units: Units = Units.Kilometers): NearestPointOnLineResult { +public fun nearestPointOnLine(line: LineString, point: Position, units: Units = Units.Kilometers): NearestPointOnLineResult { return nearestPointOnLine(listOf(line.coordinates), point, units) } @@ -125,7 +125,7 @@ fun nearestPointOnLine(line: LineString, point: Position, units: Units = Units.K * @return The closest position along the lines */ @ExperimentalTurfApi -fun nearestPointOnLine( +public fun nearestPointOnLine( lines: MultiLineString, point: Position, units: Units = Units.Kilometers diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Transformation.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Transformation.kt index 5f73d146..7d394388 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Transformation.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Transformation.kt @@ -15,7 +15,7 @@ import io.github.dellisd.spatialk.geojson.Position * @return A [LineString] containing a curved line around the positions of the input line */ @OptIn(ExperimentalTurfApi::class) -fun bezierSpline(line: LineString, duration: Int = 10_000, sharpness: Double = 0.85): LineString = +public fun bezierSpline(line: LineString, duration: Int = 10_000, sharpness: Double = 0.85): LineString = LineString(bezierSpline(line.coordAll(), duration, sharpness)) /** @@ -30,7 +30,7 @@ fun bezierSpline(line: LineString, duration: Int = 10_000, sharpness: Double = 0 * @return A [List] containing [Position] of a curved line around the positions of the input line */ @Suppress("MagicNumber") -fun bezierSpline(coords: List, duration: Int = 10_000, sharpness: Double = 0.85): List { +public fun bezierSpline(coords: List, duration: Int = 10_000, sharpness: Double = 0.85): List { // utility function to ensure a given altitude fun Position.altitude() = altitude ?: 0.0 diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Units.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Units.kt index 1b08349b..00105d67 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Units.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Units.kt @@ -1,12 +1,9 @@ package io.github.dellisd.spatialk.turf -import kotlin.native.concurrent.SharedImmutable - /** * Radius of the Earth used with the Harvesine formula. Approximated using a spherical (non-ellipsoid) Earth. */ -@SharedImmutable -const val EARTH_RADIUS = 6371008.8 +public const val EARTH_RADIUS: Double = 6371008.8 internal const val ANTIMERIDIAN_POS = 180.0 internal const val ANTIMERIDIAN_NEG = -180.0 @@ -20,7 +17,7 @@ internal const val ANTIMERIDIAN_NEG = -180.0 */ @ExperimentalTurfApi @Suppress("MagicNumber") -enum class Units(internal val unitFactor: Double, internal val factor: Double, internal val areaFactor: Double) { +public enum class Units(internal val unitFactor: Double, internal val factor: Double, internal val areaFactor: Double) { Meters(1.0, EARTH_RADIUS, 1.0), Millimeters(1000.0, EARTH_RADIUS * 1000, 1_000_000.0), Centimeters(100.0, EARTH_RADIUS * 100, 10_000.0), diff --git a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Utils.kt b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Utils.kt index 71a748b4..801b28c6 100644 --- a/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Utils.kt +++ b/turf/src/commonMain/kotlin/io/github/dellisd/spatialk/turf/Utils.kt @@ -1,7 +1,5 @@ package io.github.dellisd.spatialk.turf -import kotlin.native.concurrent.SharedImmutable - /** * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit. * @@ -14,7 +12,7 @@ import kotlin.native.concurrent.SharedImmutable * @exception IllegalArgumentException if the given units are invalid */ @ExperimentalTurfApi -fun radiansToLength(radians: Double, units: Units = Units.Kilometers): Double { +public fun radiansToLength(radians: Double, units: Units = Units.Kilometers): Double { require(!units.factor.isNaN()) { "${units.name} units is invalid" } return radians * units.factor } @@ -31,7 +29,7 @@ fun radiansToLength(radians: Double, units: Units = Units.Kilometers): Double { * @exception IllegalArgumentException if the given units are invalid */ @ExperimentalTurfApi -fun lengthToRadians(distance: Double, units: Units = Units.Kilometers): Double { +public fun lengthToRadians(distance: Double, units: Units = Units.Kilometers): Double { require(!units.factor.isNaN()) { "${units.name} units is invalid" } return distance / units.factor } @@ -48,7 +46,7 @@ fun lengthToRadians(distance: Double, units: Units = Units.Kilometers): Double { * @exception IllegalArgumentException if the given units are invalid */ @ExperimentalTurfApi -fun lengthToDegrees(distance: Double, units: Units = Units.Kilometers) = +public fun lengthToDegrees(distance: Double, units: Units = Units.Kilometers): Double = degrees( lengthToRadians( distance, @@ -67,7 +65,7 @@ fun lengthToDegrees(distance: Double, units: Units = Units.Kilometers) = * @exception IllegalArgumentException if the given length is negative */ @ExperimentalTurfApi -fun convertLength(length: Double, from: Units = Units.Meters, to: Units = Units.Kilometers): Double { +public fun convertLength(length: Double, from: Units = Units.Meters, to: Units = Units.Kilometers): Double { require(length >= 0) { "length must be a positive number" } return radiansToLength( lengthToRadians( @@ -91,7 +89,7 @@ fun convertLength(length: Double, from: Units = Units.Meters, to: Units = Units. */ @Suppress("ThrowsCount") @ExperimentalTurfApi -fun convertArea(area: Double, from: Units = Units.Meters, to: Units = Units.Kilometers): Double { +public fun convertArea(area: Double, from: Units = Units.Meters, to: Units = Units.Kilometers): Double { require(area >= 0) { "area must be a positive number" } require(!from.areaFactor.isNaN()) { "invalid original units" } require(!to.areaFactor.isNaN()) { "invalid final units" } @@ -108,7 +106,7 @@ fun convertArea(area: Double, from: Units = Units.Meters, to: Units = Units.Kilo */ @Suppress("MagicNumber") @ExperimentalTurfApi -fun bearingToAzimuth(bearing: Double): Double { +public fun bearingToAzimuth(bearing: Double): Double { var angle = bearing % 360 if (angle < 0) { angle += 360