From b06493fd6d4813c7b864330379807231419db5e8 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Wed, 13 Apr 2022 04:25:22 +0430 Subject: [PATCH] kotlin: Improve access of companions object fields/methods in Java --- generate/template/astronomy.kt | 9 +++++++-- .../kotlin/doc/-rotation-matrix/-companion/identity.md | 3 +++ source/kotlin/doc/-rotation-matrix/-companion/index.md | 2 +- .../kotlin/doc/-time/-companion/from-terrestrial-time.md | 3 +++ source/kotlin/doc/-time/-companion/index.md | 2 +- .../kotlin/io/github/cosinekitty/astronomy/astronomy.kt | 9 +++++++-- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/generate/template/astronomy.kt b/generate/template/astronomy.kt index 6575d276..0e354480 100644 --- a/generate/template/astronomy.kt +++ b/generate/template/astronomy.kt @@ -473,6 +473,7 @@ class Time private constructor( internal fun julianMillennia() = tt / DAYS_PER_MILLENNIUM companion object { + @JvmStatic private val origin = GregorianCalendar(TimeZoneUtc).also { it.set(2000, 0, 1, 12, 0, 0) it.set(Calendar.MILLISECOND, 0) @@ -480,6 +481,7 @@ class Time private constructor( private const val MILLIS_PER_DAY = 24 * 3600 * 1000 + @JvmStatic private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").also { it.timeZone = TimeZoneUtc } @@ -498,6 +500,7 @@ class Time private constructor( * * @param tt The number of days after the J2000 epoch. */ + @JvmStatic fun fromTerrestrialTime(tt: Double): Time = Time(universalTime(tt), tt) } } @@ -547,6 +550,7 @@ internal data class TerseVector(var x: Double, var y: Double, var z: Double) { } companion object { + @JvmStatic fun zero() = TerseVector(0.0, 0.0, 0.0) } } @@ -1004,7 +1008,8 @@ class RotationMatrix( * This matrix can be the starting point for other operations, * such as calling a series of [RotationMatrix.combine] or [RotationMatrix.pivot]. */ - fun identity() = RotationMatrix ( + @JvmStatic + fun identity() = RotationMatrix( 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 @@ -1989,7 +1994,7 @@ internal fun peakMoonShadow(searchCenterTime: Time): ShadowInfo { val window = 0.03 // days before/after new moon to search for minimum shadow distance val t1 = searchCenterTime.addDays(-window) val t2 = searchCenterTime.addDays(+window) - val tx = search(moonShadowSlopeContext, t1, t2, 1.0) ?: + val tx = search(t1, t2, 1.0, moonShadowSlopeContext) ?: throw InternalError("Failed to find Moon peak shadow event.") return moonShadow(tx) } diff --git a/source/kotlin/doc/-rotation-matrix/-companion/identity.md b/source/kotlin/doc/-rotation-matrix/-companion/identity.md index 4a22a118..f0249061 100644 --- a/source/kotlin/doc/-rotation-matrix/-companion/identity.md +++ b/source/kotlin/doc/-rotation-matrix/-companion/identity.md @@ -3,6 +3,9 @@ # identity [jvm]\ + +@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-static/index.html) + fun [identity](identity.md)(): [RotationMatrix](../index.md) Creates an identity rotation matrix. diff --git a/source/kotlin/doc/-rotation-matrix/-companion/index.md b/source/kotlin/doc/-rotation-matrix/-companion/index.md index 692b6a99..e2b611ea 100644 --- a/source/kotlin/doc/-rotation-matrix/-companion/index.md +++ b/source/kotlin/doc/-rotation-matrix/-companion/index.md @@ -9,4 +9,4 @@ object [Companion](index.md) | Name | Summary | |---|---| -| [identity](identity.md) | [jvm]
fun [identity](identity.md)(): [RotationMatrix](../index.md)
Creates an identity rotation matrix. | +| [identity](identity.md) | [jvm]
@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-static/index.html)
fun [identity](identity.md)(): [RotationMatrix](../index.md)
Creates an identity rotation matrix. | diff --git a/source/kotlin/doc/-time/-companion/from-terrestrial-time.md b/source/kotlin/doc/-time/-companion/from-terrestrial-time.md index f99e4846..c71c39ff 100644 --- a/source/kotlin/doc/-time/-companion/from-terrestrial-time.md +++ b/source/kotlin/doc/-time/-companion/from-terrestrial-time.md @@ -3,6 +3,9 @@ # fromTerrestrialTime [jvm]\ + +@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-static/index.html) + fun [fromTerrestrialTime](from-terrestrial-time.md)(tt: [Double](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html)): [Time](../index.md) Creates a Time object from a Terrestrial Time day value. diff --git a/source/kotlin/doc/-time/-companion/index.md b/source/kotlin/doc/-time/-companion/index.md index b8354a19..cea2d8fe 100644 --- a/source/kotlin/doc/-time/-companion/index.md +++ b/source/kotlin/doc/-time/-companion/index.md @@ -9,4 +9,4 @@ object [Companion](index.md) | Name | Summary | |---|---| -| [fromTerrestrialTime](from-terrestrial-time.md) | [jvm]
fun [fromTerrestrialTime](from-terrestrial-time.md)(tt: [Double](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html)): [Time](../index.md)
Creates a Time object from a Terrestrial Time day value. | +| [fromTerrestrialTime](from-terrestrial-time.md) | [jvm]
@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-static/index.html)
fun [fromTerrestrialTime](from-terrestrial-time.md)(tt: [Double](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html)): [Time](../index.md)
Creates a Time object from a Terrestrial Time day value. | diff --git a/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt b/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt index 1a611fc1..cb77c82c 100644 --- a/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt +++ b/source/kotlin/src/main/kotlin/io/github/cosinekitty/astronomy/astronomy.kt @@ -473,6 +473,7 @@ class Time private constructor( internal fun julianMillennia() = tt / DAYS_PER_MILLENNIUM companion object { + @JvmStatic private val origin = GregorianCalendar(TimeZoneUtc).also { it.set(2000, 0, 1, 12, 0, 0) it.set(Calendar.MILLISECOND, 0) @@ -480,6 +481,7 @@ class Time private constructor( private const val MILLIS_PER_DAY = 24 * 3600 * 1000 + @JvmStatic private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").also { it.timeZone = TimeZoneUtc } @@ -498,6 +500,7 @@ class Time private constructor( * * @param tt The number of days after the J2000 epoch. */ + @JvmStatic fun fromTerrestrialTime(tt: Double): Time = Time(universalTime(tt), tt) } } @@ -547,6 +550,7 @@ internal data class TerseVector(var x: Double, var y: Double, var z: Double) { } companion object { + @JvmStatic fun zero() = TerseVector(0.0, 0.0, 0.0) } } @@ -1004,7 +1008,8 @@ class RotationMatrix( * This matrix can be the starting point for other operations, * such as calling a series of [RotationMatrix.combine] or [RotationMatrix.pivot]. */ - fun identity() = RotationMatrix ( + @JvmStatic + fun identity() = RotationMatrix( 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 @@ -1989,7 +1994,7 @@ internal fun peakMoonShadow(searchCenterTime: Time): ShadowInfo { val window = 0.03 // days before/after new moon to search for minimum shadow distance val t1 = searchCenterTime.addDays(-window) val t2 = searchCenterTime.addDays(+window) - val tx = search(moonShadowSlopeContext, t1, t2, 1.0) ?: + val tx = search(t1, t2, 1.0, moonShadowSlopeContext) ?: throw InternalError("Failed to find Moon peak shadow event.") return moonShadow(tx) }