Last active
February 14, 2018 15:44
-
-
Save ivankeller/4533a0ce4a2a97f66b9928e129b8bcea to your computer and use it in GitHub Desktop.
Function that tests if a point belongs to a interval modulo (i.e. an arc of circle)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def belongs_to(t, a, b): | |
"""Return True if t belongs to real number interval [a, b], False otherwise.""" | |
return t >= a and t <= b | |
def is_in_arc(t, a, b, m=365): | |
"""Return True if t is in the interval [a, b] modulo m, False otherwise""" | |
t, a, b = [x % m for x in (t, a, b)] # convert all the values to their values modulo m | |
if a < b: | |
return belongs_to(t, a, b) | |
else: | |
return not belongs_to(t, b, a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful for testing if a day-of-year is on a given day-of-year interval