Class: Is

Inherits:
Object
  • Object
show all
Defined in:
lib/is.rb,
lib/is/area.rb,
lib/is/point.rb,
lib/is/version.rb

Defined Under Namespace

Classes: Area, Point

Constant Summary collapse

VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.all_points(points) ⇒ Object Also known as: points



12
13
14
15
16
17
18
19
20
21
# File 'lib/is.rb', line 12

def all_points(points)
  pts = points.clone

  pts.define_singleton_method :in?, ->(area) do
    area = Area.new area
    all? { |point| Point.new(*point).in? area }
  end

  pts
end

.all_points_in_area?(points, area) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/is.rb', line 61

def all_points_in_area?(points, area)
  all_points(points).in?(area)
end

.any_points(points) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/is.rb', line 24

def any_points(points)
  pts = points.clone

  pts.define_singleton_method :in?, ->(area) do
    area = Area.new area
    any? { |point| Point.new(*point).in? area }
  end

  pts
end

.any_points_in_area?(points, area) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/is.rb', line 65

def any_points_in_area?(points, area)
  any_points(points).in?(area)
end

.first(points) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/is.rb', line 46

def first(points)
  pts = points.clone

  pts.define_singleton_method :in, ->(area) do
    area = Area.new area
    find { |point| Point.new(*point).in? area }
  end

  pts
end

.first_point_in_area(points, area) ⇒ Object



73
74
75
# File 'lib/is.rb', line 73

def first_point_in_area(points, area)
  first(points).in(area)
end

.point(point) ⇒ Object



8
9
10
# File 'lib/is.rb', line 8

def point(point)
  Point.new *point
end

.point_in_area?(point, area) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/is.rb', line 57

def point_in_area?(point, area)
  point(point).in? area
end

.select(points) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/is.rb', line 35

def select(points)
  pts = points.clone

  pts.define_singleton_method :in, ->(area) do
    area = Area.new area
    select { |point| Point.new(*point).in? area }
  end

  pts
end

.select_points_in_area(points, area) ⇒ Object



69
70
71
# File 'lib/is.rb', line 69

def select_points_in_area(points, area)
  select(points).in(area)
end