Class: Contrek::Reducers::VisvalingamReducer

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points: list_of_points, options: {}) ⇒ VisvalingamReducer

Returns a new instance of VisvalingamReducer.



9
10
11
12
13
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 9

def initialize(points: list_of_points, options: {})
  @pts = points
  given_tolerance = options[:visvalingam_tolerance] || 10.0
  @tolerance = given_tolerance * given_tolerance
end

Class Method Details

.simplify(pts, distance_tolerance) ⇒ Object



19
20
21
22
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 19

def self.simplify(pts, distance_tolerance)
  simp = Polygon::Reducers::VisvalingamReducer.new(pts, distance_tolerance)
  simp.simplify
end

Instance Method Details

#reduce!Object



15
16
17
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 15

def reduce!
  @pts.replace simplify
end

#simplifyObject



24
25
26
27
28
29
30
31
32
# File 'lib/contrek/reducers/visvalingam_reducer.rb', line 24

def simplify
  vw_line = Vertex.build_line(@pts)
  min_area = @tolerance
  loop do
    min_area = simplify_vertex(vw_line)
    break if min_area >= @tolerance
  end
  vw_line.get_coordinates
end