Class: Contrek::Reducers::DouglasPeuckerReducer

Inherits:
Reducer
  • Object
show all
Defined in:
lib/contrek/reducers/douglas_peucker_reducer.rb

Constant Summary collapse

TOLERANCE_SQUARED =
1.0

Instance Method Summary collapse

Methods inherited from Reducer

#initialize

Constructor Details

This class inherits a constructor from Contrek::Reducers::Reducer

Instance Method Details

#reduce!Object



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

def reduce!
  count = @points.length
  return @points if count < 4

  first_index = extreme_index_by_x
  second_index = farthest_index_from(first_index)

  return @points if second_index == first_index

  keep = Array.new(count, false)
  keep[first_index] = true
  keep[second_index] = true

  simplify_arc!(first_index, second_index, keep)
  simplify_arc!(second_index, first_index, keep)

  compact_ring!(keep)
end