Class: SimplifyRb::Simplifier

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

Instance Method Summary collapse

Instance Method Details

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

Raises:

  • (ArgumentError)


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

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

  return raw_points if raw_points.length <= 1

  sq_tolerance = tolerance * tolerance

  points = raw_points.map { |p| Point.new(p) }

  unless highest_quality
    points = RadialDistanceSimplifier.new.process(points, sq_tolerance)
  end

  DouglasPeuckerSimplifier.new
    .process(points, sq_tolerance)
    .map(&:original_entity)
end