Class: ClusterCalculator::Cluster
- Inherits:
-
Object
- Object
- ClusterCalculator::Cluster
- Defined in:
- lib/quadtone/cluster_calculator.rb
Instance Attribute Summary collapse
-
#center ⇒ Object
Returns the value of attribute center.
-
#moved ⇒ Object
Returns the value of attribute moved.
-
#samples ⇒ Object
Returns the value of attribute samples.
Instance Method Summary collapse
- #add_sample(sample) ⇒ Object
- #clear_samples ⇒ Object
- #distance_to(sample) ⇒ Object
-
#initialize(center) ⇒ Cluster
constructor
A new instance of Cluster.
- #size ⇒ Object
- #update_center(delta = 0.001) ⇒ Object
Constructor Details
#initialize(center) ⇒ Cluster
Returns a new instance of Cluster.
13 14 15 16 17 |
# File 'lib/quadtone/cluster_calculator.rb', line 13 def initialize(center) @center = center @samples = [] @moved = true end |
Instance Attribute Details
#center ⇒ Object
Returns the value of attribute center.
9 10 11 |
# File 'lib/quadtone/cluster_calculator.rb', line 9 def center @center end |
#moved ⇒ Object
Returns the value of attribute moved.
11 12 13 |
# File 'lib/quadtone/cluster_calculator.rb', line 11 def moved @moved end |
#samples ⇒ Object
Returns the value of attribute samples.
10 11 12 |
# File 'lib/quadtone/cluster_calculator.rb', line 10 def samples @samples end |
Instance Method Details
#add_sample(sample) ⇒ Object
19 20 21 |
# File 'lib/quadtone/cluster_calculator.rb', line 19 def add_sample(sample) @samples << sample end |
#clear_samples ⇒ Object
23 24 25 |
# File 'lib/quadtone/cluster_calculator.rb', line 23 def clear_samples @samples = [] end |
#distance_to(sample) ⇒ Object
27 28 29 |
# File 'lib/quadtone/cluster_calculator.rb', line 27 def distance_to(sample) @center.delta_e(sample.output) end |
#size ⇒ Object
40 41 42 |
# File 'lib/quadtone/cluster_calculator.rb', line 40 def size @samples.length end |
#update_center(delta = 0.001) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/quadtone/cluster_calculator.rb', line 31 def update_center(delta=0.001) @moved = false average, error = Color::Lab.average(@samples.map(&:output)) unless average.delta_e(@center) < delta @center = average @moved = true end end |