Skip to content

Added check that an Interval is an Interval; improved readability #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/utils/frames/worlds/geometrical-worlds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
y :: T
end

An interval in a 1-dimensional space, with coordinates of type `T`.
An interval in a 1-dimensional space, with coordinates of type `T`, such that x<y.

# Examples
```julia-repl
Expand Down Expand Up @@ -123,13 +123,14 @@
x :: T
y :: T

# TODO needed?
Interval(w::Interval) = Interval(w.x,w.y)

Interval{T}(x::T,y::T) where {T} = new{T}(x,y)
function Interval{T}(x::T,y::T) where {T}
if x<-1 || x >= y
error("Cannot instantiate Interval(x={$x},y={$y})")

Check warning on line 128 in src/utils/frames/worlds/geometrical-worlds.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/frames/worlds/geometrical-worlds.jl#L128

Added line #L128 was not covered by tests
end
return new{T}(x,y)
end
Interval(x::T,y::T) where {T} = Interval{T}(x,y)
# TODO: perhaps check x<y (and x<=N, y<=N ?), but only in debug mode.
# Interval(x,y) = x>0 && y>0 && x < y ? new(x,y) : error("Cannot instantiate Interval(x={$x},y={$y})")
Interval(w::Interval) = Interval(w.x,w.y)

Check warning on line 133 in src/utils/frames/worlds/geometrical-worlds.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/frames/worlds/geometrical-worlds.jl#L133

Added line #L133 was not covered by tests
end

# Base.size(w::Interval) = (Base.length(w),)
Expand Down
Loading