Class: Draught::PathCleaner
- Inherits:
-
Object
- Object
- Draught::PathCleaner
- Defined in:
- lib/draught/path_cleaner.rb
Instance Attribute Summary collapse
-
#input_points ⇒ Object
readonly
Returns the value of attribute input_points.
Class Method Summary collapse
Instance Method Summary collapse
- #dedupe ⇒ Object
-
#initialize(input_points) ⇒ PathCleaner
constructor
A new instance of PathCleaner.
- #simplify ⇒ Object
Constructor Details
#initialize(input_points) ⇒ PathCleaner
Returns a new instance of PathCleaner.
15 16 17 |
# File 'lib/draught/path_cleaner.rb', line 15 def initialize(input_points) @input_points = input_points end |
Instance Attribute Details
#input_points ⇒ Object (readonly)
Returns the value of attribute input_points.
13 14 15 |
# File 'lib/draught/path_cleaner.rb', line 13 def input_points @input_points end |
Class Method Details
Instance Method Details
#dedupe ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/draught/path_cleaner.rb', line 19 def dedupe output_points = [input_points.first] input_points.inject do |previous_point, point| output_points << point if point != previous_point point end output_points end |
#simplify ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/draught/path_cleaner.rb', line 28 def simplify points = dedupe pos = 0 while pos < (points.length - 2) triple = points[pos, 3] if intercepts?(*triple) points.delete_at(pos + 1) else pos += 1 end end points end |