Created
February 12, 2013 18:39
-
-
Save tomelm/4772139 to your computer and use it in GitHub Desktop.
figure out if a simple polygon is valid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point | |
attr_accessor :x, :y | |
end | |
class SimplePolygon | |
def initialize(points) | |
@points = points | |
@lines = [] | |
end | |
def is_valid? | |
i = 0 | |
while i < @lines.size | |
intersects?(@lines[i], @lines[i+1]) | |
end | |
true | |
end | |
def create_lines | |
i = 0 | |
while i < @points.size | |
@lines.append([@point[i], @points[i+1]]) | |
i += 1 | |
end | |
@lines.append([@point.last, @point.first]) | |
@lines | |
end | |
def intersects?(line1, line2) | |
return true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment