Skip to content

Commit

Permalink
Add refraction option for more methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Dec 28, 2022
1 parent c436228 commit 7f63bdf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
ext.groupId = 'com.kylecorry.sol'
ext.versionName = '6.2.1'
ext.versionName = '6.2.2'
}

allprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,19 @@ object Astronomy : IAstronomyService {
override fun getDaylightLength(
date: ZonedDateTime,
location: Coordinate,
sunTimesMode: SunTimesMode
sunTimesMode: SunTimesMode,
withRefraction: Boolean
): Duration {
val startOfDay = date.atStartOfDay()
val sunrise = getNextSunrise(startOfDay, location, sunTimesMode)
val sunset = getNextSunset(startOfDay, location, sunTimesMode)
val sunrise = getNextSunrise(startOfDay, location, sunTimesMode, withRefraction)
val sunset = getNextSunset(startOfDay, location, sunTimesMode, withRefraction)

if (sunrise != null && sunset != null && sunset > sunrise) {
// Rise in morning, set at night
return Duration.between(sunrise, sunset)
} else if (sunrise == null && sunset == null) {
// Sun doesn't rise or set
return if (isSunUp(startOfDay, location)) Duration.between(
return if (isSunUp(startOfDay, location, withRefraction)) Duration.between(
startOfDay,
startOfDay.plusDays(1)
) else Duration.ZERO
Expand All @@ -136,17 +137,32 @@ object Astronomy : IAstronomyService {
return sun.getDistance(time.toUniversalTime())
}

override fun getSolarRadiation(date: ZonedDateTime, location: Coordinate): Double {
return radiation.getRadiation(date.toUniversalTime(), location)
override fun getSolarRadiation(
date: ZonedDateTime,
location: Coordinate,
withRefraction: Boolean
): Double {
return radiation.getRadiation(
date.toUniversalTime(),
location,
withRefraction = withRefraction
)
}

override fun getSolarRadiation(
date: ZonedDateTime,
location: Coordinate,
tilt: Float,
azimuth: Bearing
azimuth: Bearing,
withRefraction: Boolean
): Double {
return radiation.getRadiation(date.toUniversalTime(), location, tilt, azimuth)
return radiation.getRadiation(
date.toUniversalTime(),
location,
tilt,
azimuth,
withRefraction
)
}

override fun getMoonEvents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ interface ISunService {
fun getDaylightLength(
date: ZonedDateTime,
location: Coordinate,
sunTimesMode: SunTimesMode = SunTimesMode.Actual
sunTimesMode: SunTimesMode = SunTimesMode.Actual,
withRefraction: Boolean = false
): Duration

fun getSunDistance(time: ZonedDateTime): Distance

/**
* Gets the solar radiation for the given time in kW/m^2
*/
fun getSolarRadiation(date: ZonedDateTime, location: Coordinate): Double
fun getSolarRadiation(
date: ZonedDateTime,
location: Coordinate,
withRefraction: Boolean = false
): Double

/**
* Gets the solar radiation for the given time in kW/m^2
Expand All @@ -59,7 +64,8 @@ interface ISunService {
date: ZonedDateTime,
location: Coordinate,
tilt: Float,
azimuth: Bearing
azimuth: Bearing,
withRefraction: Boolean = false
): Double

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ internal class SolarRadiationCalculator {
ut: UniversalTime,
location: Coordinate,
tilt: Float? = null,
bearing: Bearing? = null
bearing: Bearing? = null,
withRefraction: Boolean = false
): Double {
val altitude = AstroUtils.getAltitude(sun, ut, location, false).toDouble()
val altitude = AstroUtils.getAltitude(sun, ut, location, withRefraction).toDouble()
if (altitude < 0) {
return 0.0
}
Expand Down

0 comments on commit 7f63bdf

Please sign in to comment.