Skip to content

Instantly share code, notes, and snippets.

@tomelm
Created February 12, 2013 18:39
Show Gist options
  • Save tomelm/4772139 to your computer and use it in GitHub Desktop.
Save tomelm/4772139 to your computer and use it in GitHub Desktop.
figure out if a simple polygon is valid
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