Class: EightCorner::Point

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

Overview

A point on a 2D plane.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = nil, y = nil) ⇒ Point

Returns a new instance of Point.



20
21
22
23
# File 'lib/eight_corner/point.rb', line 20

def initialize(x=nil, y=nil)
  @x = x
  @y = y
end

Instance Attribute Details

#angle_from_lastObject

Returns the value of attribute angle_from_last.



6
7
8
# File 'lib/eight_corner/point.rb', line 6

def angle_from_last
  @angle_from_last
end

#angle_pctObject

Returns the value of attribute angle_pct.



6
7
8
# File 'lib/eight_corner/point.rb', line 6

def angle_pct
  @angle_pct
end

#boundsObject

Returns the value of attribute bounds.



6
7
8
# File 'lib/eight_corner/point.rb', line 6

def bounds
  @bounds
end

#created_by_potentialObject

Returns the value of attribute created_by_potential.



6
7
8
# File 'lib/eight_corner/point.rb', line 6

def created_by_potential
  @created_by_potential
end

#distance_from_lastObject

Returns the value of attribute distance_from_last.



6
7
8
# File 'lib/eight_corner/point.rb', line 6

def distance_from_last
  @distance_from_last
end

#distance_pctObject

Returns the value of attribute distance_pct.



6
7
8
# File 'lib/eight_corner/point.rb', line 6

def distance_pct
  @distance_pct
end

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/eight_corner/point.rb', line 6

def x
  @x
end

#yObject

Returns the value of attribute y.



6
7
8
# File 'lib/eight_corner/point.rb', line 6

def y
  @y
end

Instance Method Details

#==(other) ⇒ Object



55
56
57
# File 'lib/eight_corner/point.rb', line 55

def ==(other)
  x == other.x && y == other.y
end

#angle_rangeObject



31
32
33
# File 'lib/eight_corner/point.rb', line 31

def angle_range
  Quadrant.angle_range_for(quadrant)
end

#maxObject



47
48
49
# File 'lib/eight_corner/point.rb', line 47

def max
  [@x,@y].max
end

#max_isObject



51
52
53
# File 'lib/eight_corner/point.rb', line 51

def max_is
  @x > @y ? :x : :y
end

#potentialObject

a single % value based on the data in this point used as an input for another Base#plot call TODO: what is distribution of values of this function? we want something reasonably gaussian, i think.

w/o created_by_potential, rearranging the initial string in a series of figures alters the first 10 figures or so, and then they eventually converge back to being identical. (The ~11th figure shows no dependence on this initial change in ordering.)



43
44
45
# File 'lib/eight_corner/point.rb', line 43

def potential
  (x/bounds.x.to_f + y/bounds.y.to_f + distance_pct.to_f + angle_pct.to_f + created_by_potential.to_f) % 1
end

#quadrantObject

which quadrant of the Bounds is this point in?



26
27
28
29
# File 'lib/eight_corner/point.rb', line 26

def quadrant
  raise "cannot calculate quadrant. bounds is nil" if bounds.nil?
  @quadrant ||= bounds.quadrant(self)
end

#valid?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/eight_corner/point.rb', line 59

def valid?
  x >= 0 && y >= 0 && x <= bounds.x && y <= bounds.y
end