Skip to content

Instantly share code, notes, and snippets.

@RavensKrag
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RavensKrag/f64eae75de5e4eb68378 to your computer and use it in GitHub Desktop.
Save RavensKrag/f64eae75de5e4eb68378 to your computer and use it in GitHub Desktop.
Better interface to get Chipmunk verts (still kinda messy)
module CP
module Shape
class Poly
# return an array of all vertices
def verts
out = Array.new(self.num_verts)
self.num_verts.times do |i|
out[i] = self.vert(i)
end
return out
end
def area
CP.area_for_poly self.verts
end
include Enumerable
def each
self.num_verts.times do |i|
yield self.vert(i)
end
end
alias :each_vert :each
alias :each_vert_with_index :each_with_index
alias :each_vert_with_object :each_with_object
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment