Class: PoissonDiskSampling::SampleArea

Inherits:
Object
  • Object
show all
Defined in:
lib/poisson_disk_sampling/sample_area.rb

Overview

Encapsulates area to be sampled by poisson disk sampling

Instance Method Summary collapse

Constructor Details

#initialize(grid:) ⇒ SampleArea

Returns a new instance of SampleArea.



8
9
10
11
# File 'lib/poisson_disk_sampling/sample_area.rb', line 8

def initialize(grid:)
  @grid = grid.dup
  @points = Array.new(height) { Array.new(width) { false } }
end

Instance Method Details

#[](x, y) ⇒ Object



26
27
28
# File 'lib/poisson_disk_sampling/sample_area.rb', line 26

def [](x, y)
  @grid[y][x]
end

#heightObject



13
14
15
# File 'lib/poisson_disk_sampling/sample_area.rb', line 13

def height
  @grid.length
end

#point_within_bounds?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/poisson_disk_sampling/sample_area.rb', line 34

def point_within_bounds?(x, y)
  y >= 0 && y < height && x >= 0 && x < width
end

#point_within_bounds_and_can_have_road?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/poisson_disk_sampling/sample_area.rb', line 38

def point_within_bounds_and_can_have_road?(x, y)
  point_within_bounds?(x, y) && @grid[y][x].can_haz_road?
end

#sampled_point?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/poisson_disk_sampling/sample_area.rb', line 30

def sampled_point?(x, y)
  @points[y][x]
end

#set_sampled_point(x, y) ⇒ Object

rubocop:disable Naming/MethodParameterName:



22
23
24
# File 'lib/poisson_disk_sampling/sample_area.rb', line 22

def set_sampled_point(x, y)
  @points[y][x] = true
end

#widthObject



17
18
19
# File 'lib/poisson_disk_sampling/sample_area.rb', line 17

def width
  @grid[0].length
end