Class: WindingPolygon::Point
- Inherits:
-
Object
- Object
- WindingPolygon::Point
- Defined in:
- lib/winding-polygon/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #<(other_point) ⇒ Object
- #<=>(other_point) ⇒ Object
- #==(other_point) ⇒ Object
- #>(other_point) ⇒ Object
-
#compare(other_point) ⇒ Object
Determines the xy lexicographical order of two points.
-
#initialize(x, y) ⇒ Point
constructor
A new instance of Point.
-
#is_left(p0, p1) ⇒ Object
tests if point is Left|On|Right of the line P0 to P1.
Constructor Details
#initialize(x, y) ⇒ Point
Returns a new instance of Point.
7 8 9 10 |
# File 'lib/winding-polygon/point.rb', line 7 def initialize(x,y) @x=x @y=y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
4 5 6 |
# File 'lib/winding-polygon/point.rb', line 4 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/winding-polygon/point.rb', line 5 def y @y end |
Instance Method Details
#<(other_point) ⇒ Object
45 46 47 48 49 |
# File 'lib/winding-polygon/point.rb', line 45 def < (other_point) return true if @x < other_point.x return true if @x == other_point.x && @y < other_point.y return false end |
#<=>(other_point) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/winding-polygon/point.rb', line 27 def <=> other_point raise Exception.new("Self is x=#{@x},y=#{@y}, the other_point is nil") if other_point.nil? # x-coord first return 1 if @x > other_point.x return -1 if @x < other_point.x # y-coord second return 1 if @y > other_point.y return -1 if @y < other_point.y # they are the same point return 0 end |
#==(other_point) ⇒ Object
41 42 43 |
# File 'lib/winding-polygon/point.rb', line 41 def == (other_point) @x==other_point.x && @y==other_point.y end |
#>(other_point) ⇒ Object
51 52 53 54 55 |
# File 'lib/winding-polygon/point.rb', line 51 def > (other_point) return true if @x > other_point.x return true if @x == other_point.x && @y > other_point.y return false end |
#compare(other_point) ⇒ Object
Determines the xy lexicographical order of two points
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/winding-polygon/point.rb', line 13 def compare other_point raise Exception.new("Self is x=#{@x},y=#{@y}, the other_point is nil") if other_point.nil? # x-coord first return 1 if @x > other_point.x return -1 if @x < other_point.x # y-coord second return 1 if @y > other_point.y return -1 if @y < other_point.y # they are the same point return 0 end |
#is_left(p0, p1) ⇒ Object
tests if point is Left|On|Right of the line P0 to P1.
returns:
>0 for left of the line
0 for on the line
<0 for right of the line
63 64 65 |
# File 'lib/winding-polygon/point.rb', line 63 def is_left p0, p1 return (p1.x - p0.x) * (@y - p0.y) - (@x - p0.x) * (p1.y - p0.y) end |