Class: SimplifyRb::Simplifier

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

Instance Method Summary collapse

Instance Method Details

#process(points, tolerance = 1, highest_quality = false) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simplify_rb.rb', line 6

def process(points, tolerance = 1, highest_quality = false)
  raise ArgumentError.new('Points must be an array') unless points.is_a? Array

  return points if points.length <= 1

  symbolizer = Symbolizer.new

  points = symbolizer.symbolize_keys(points) unless points.all? { |p| symbolizer.keys_are_symbols?(p.keys) }

  sq_tolerance = tolerance * tolerance

  # Optimisation step 1
  points = simplify_radial_dist(points, sq_tolerance) unless highest_quality

  # Optimisation step 2
  simplify_douglas_peucker(points, sq_tolerance)
end