Class: PoissonDiskSampling::Sampler

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

Overview

Generates X randomly distributed points within given 2D space using possion disk sampling

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sample_area:, num_attempts: 20, seed: rand) ⇒ Sampler

Returns a new instance of Sampler.



12
13
14
15
16
# File 'lib/poisson_disk_sampling/sampler.rb', line 12

def initialize(sample_area:, num_attempts: 20, seed: rand)
  @sample_area = sample_area
  @num_attempts = num_attempts
  @seed = seed
end

Instance Attribute Details

#num_attemptsObject (readonly)

Returns the value of attribute num_attempts.



10
11
12
# File 'lib/poisson_disk_sampling/sampler.rb', line 10

def num_attempts
  @num_attempts
end

#sample_areaObject (readonly)

Returns the value of attribute sample_area.



10
11
12
# File 'lib/poisson_disk_sampling/sampler.rb', line 10

def sample_area
  @sample_area
end

#seedObject (readonly)

Returns the value of attribute seed.



10
11
12
# File 'lib/poisson_disk_sampling/sampler.rb', line 10

def seed
  @seed
end

Instance Method Details

#generate_points(num_of_points, radius, intial_start_point = nil) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
# File 'lib/poisson_disk_sampling/sampler.rb', line 18

def generate_points(num_of_points, radius, intial_start_point = nil)
  raise ArgumentError, "invalid start argument #{intial_start_point}" if !intial_start_point.nil? && !intial_start_point.is_a?(Array) && intial_start_point.length != 1

  retreive_points_until_active_list_empty_or_num_points_reached(intial_start_point || generate_and_assign_initial_point, num_of_points, radius)
end