lib/interval_notation.rb in interval_notation-0.1.3 vs lib/interval_notation.rb in interval_notation-0.2.0
- old
+ new
@@ -1,10 +1,10 @@
require_relative 'interval_notation/version'
require_relative 'interval_notation/error'
require_relative 'interval_notation/basic_intervals'
-require_relative 'interval_notation/combiners'
+require_relative 'interval_notation/sweep_line'
require_relative 'interval_notation/interval_set'
require_relative 'interval_notation/operations'
module IntervalNotation
UNION_SYMBOL = '∪'.freeze
@@ -19,104 +19,128 @@
# Long syntax for interval factory methods
module Short
R = ::IntervalNotation::R
Empty = ::IntervalNotation::Empty
- def int(str)
- IntervalSet.from_string(str)
+ def oo_basic(from, to)
+ BasicIntervals::OpenOpenInterval.new(from, to)
end
- def oo(from, to)
- IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(from, to)] )
+ def co_basic(from, to)
+ BasicIntervals::ClosedOpenInterval.new(from, to)
end
- def co(from, to)
- IntervalSet.new_unsafe( [BasicIntervals::ClosedOpenInterval.new(from, to)] )
+ def oc_basic(from, to)
+ BasicIntervals::OpenClosedInterval.new(from, to)
end
- def oc(from, to)
- IntervalSet.new_unsafe( [BasicIntervals::OpenClosedInterval.new(from, to)] )
- end
-
- def cc(from, to)
+ def cc_basic(from, to)
if from != to
- IntervalSet.new_unsafe( [BasicIntervals::ClosedClosedInterval.new(from, to)] )
+ BasicIntervals::ClosedClosedInterval.new(from, to)
else
- IntervalSet.new_unsafe( [BasicIntervals::Point.new(from)] )
+ BasicIntervals::Point.new(from)
end
end
- def pt(value)
- IntervalSet.new_unsafe( [BasicIntervals::Point.new(value)] )
+ def pt_basic(value)
+ BasicIntervals::Point.new(value)
end
- def lt(value)
- IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(-Float::INFINITY, value)] )
+ def lt_basic(value)
+ BasicIntervals::OpenOpenInterval.new(-Float::INFINITY, value)
end
- def le(value)
- IntervalSet.new_unsafe( [BasicIntervals::OpenClosedInterval.new(-Float::INFINITY, value)] )
+ def le_basic(value)
+ BasicIntervals::OpenClosedInterval.new(-Float::INFINITY, value)
end
- def gt(value)
- IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(value, Float::INFINITY)] )
+ def gt_basic(value)
+ BasicIntervals::OpenOpenInterval.new(value, Float::INFINITY)
end
- def ge(value)
- IntervalSet.new_unsafe( [BasicIntervals::ClosedOpenInterval.new(value, Float::INFINITY)] )
+ def ge_basic(value)
+ BasicIntervals::ClosedOpenInterval.new(value, Float::INFINITY)
end
- module_function :oo, :co, :oc, :cc, :pt, :lt, :le, :gt, :ge, :int
+ module_function :oo_basic, :co_basic, :oc_basic, :cc_basic, :pt_basic, :lt_basic, :le_basic, :gt_basic, :ge_basic
+
+ def interval(str)
+ IntervalSet.from_string(str)
+ end
+
+ def oo(from, to); IntervalSet.new_unsafe( [oo_basic(from, to)] ); end
+ def co(from, to); IntervalSet.new_unsafe( [co_basic(from, to)] ); end
+ def oc(from, to); IntervalSet.new_unsafe( [oc_basic(from, to)] ); end
+ def cc(from, to); IntervalSet.new_unsafe( [cc_basic(from, to)] ); end
+ def pt(value); IntervalSet.new_unsafe( [pt_basic(value)] ); end
+ def lt(value); IntervalSet.new_unsafe( [lt_basic(value)] ); end
+ def le(value); IntervalSet.new_unsafe( [le_basic(value)] ); end
+ def gt(value); IntervalSet.new_unsafe( [gt_basic(value)] ); end
+ def ge(value); IntervalSet.new_unsafe( [ge_basic(value)] ); end
+ module_function :oo, :co, :oc, :cc, :pt, :lt, :le, :gt, :ge, :interval
end
# Long syntax for interval factory methods
module Long
R = ::IntervalNotation::R
Empty = ::IntervalNotation::Empty
- def interval(str)
- IntervalSet.from_string(str)
+ def open_open_basic(from, to)
+ BasicIntervals::OpenOpenInterval.new(from, to)
end
- def open_open(from, to)
- IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(from, to)] )
+ def closed_open_basic(from, to)
+ BasicIntervals::ClosedOpenInterval.new(from, to)
end
- def closed_open(from, to)
- IntervalSet.new_unsafe( [BasicIntervals::ClosedOpenInterval.new(from, to)] )
+ def open_closed_basic(from, to)
+ BasicIntervals::OpenClosedInterval.new(from, to)
end
- def open_closed(from, to)
- IntervalSet.new_unsafe( [BasicIntervals::OpenClosedInterval.new(from, to)] )
- end
-
- def closed_closed(from, to)
+ def closed_closed_basic(from, to)
if from != to
- IntervalSet.new_unsafe( [BasicIntervals::ClosedClosedInterval.new(from, to)] )
+ BasicIntervals::ClosedClosedInterval.new(from, to)
else
- IntervalSet.new_unsafe( [BasicIntervals::Point.new(from)] )
+ BasicIntervals::Point.new(from)
end
end
- def point(value)
- IntervalSet.new_unsafe( [BasicIntervals::Point.new(value)] )
+ def point_basic(value)
+ BasicIntervals::Point.new(value)
end
- def less_than(value)
- IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(-Float::INFINITY, value)] )
+ def less_than_basic(value)
+ BasicIntervals::OpenOpenInterval.new(-Float::INFINITY, value)
end
- def less_than_or_equal_to(value)
- IntervalSet.new_unsafe( [BasicIntervals::OpenClosedInterval.new(-Float::INFINITY, value)] )
+ def less_than_or_equal_to_basic(value)
+ BasicIntervals::OpenClosedInterval.new(-Float::INFINITY, value)
end
- def greater_than(value)
- IntervalSet.new_unsafe( [BasicIntervals::OpenOpenInterval.new(value, Float::INFINITY)] )
+ def greater_than_basic(value)
+ BasicIntervals::OpenOpenInterval.new(value, Float::INFINITY)
end
- def greater_than_or_equal_to(value)
- IntervalSet.new_unsafe( [BasicIntervals::ClosedOpenInterval.new(value, Float::INFINITY)] )
+ def greater_than_or_equal_to_basic(value)
+ BasicIntervals::ClosedOpenInterval.new(value, Float::INFINITY)
end
+
+ module_function :open_open_basic, :closed_open_basic, :open_closed_basic, :closed_closed_basic, :point_basic,
+ :less_than_basic, :less_than_or_equal_to_basic, :greater_than_basic, :greater_than_or_equal_to_basic
+
+ def interval(str)
+ IntervalSet.from_string(str)
+ end
+
+ def open_open(from, to); IntervalSet.new_unsafe([ open_open_basic(from, to) ]); end
+ def closed_open(from, to); IntervalSet.new_unsafe([ closed_open_basic(from, to) ]); end
+ def open_closed(from, to); IntervalSet.new_unsafe([ open_closed_basic(from, to) ]); end
+ def closed_closed(from, to); IntervalSet.new_unsafe([ closed_closed_basic(from, to) ]); end
+ def point(value); IntervalSet.new_unsafe([ point_basic(value) ]); end
+ def less_than(value); IntervalSet.new_unsafe([ less_than_basic(value) ]); end
+ def less_than_or_equal_to(value); IntervalSet.new_unsafe([ less_than_or_equal_to_basic(value) ]); end
+ def greater_than(value); IntervalSet.new_unsafe([ greater_than_basic(value) ]); end
+ def greater_than_or_equal_to(value); IntervalSet.new_unsafe([ greater_than_or_equal_to_basic(value) ]); end
module_function :open_open, :closed_open, :open_closed, :closed_closed, :point,
:less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to,
:interval
end