diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-08-26 20:29:25 +0200 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-08-26 20:29:25 +0200 |
commit | 2750bc0277c3d929603daceee2e8a1e88368a306 (patch) | |
tree | 2db8bdecf84971e550bacb7737a1c19ababb87df /src/main/scala/sims/collision/Polygon.scala | |
download | sims2-2750bc0277c3d929603daceee2e8a1e88368a306.tar.gz sims2-2750bc0277c3d929603daceee2e8a1e88368a306.tar.bz2 sims2-2750bc0277c3d929603daceee2e8a1e88368a306.zip |
import from local directory
Diffstat (limited to 'src/main/scala/sims/collision/Polygon.scala')
-rw-r--r-- | src/main/scala/sims/collision/Polygon.scala | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main/scala/sims/collision/Polygon.scala b/src/main/scala/sims/collision/Polygon.scala new file mode 100644 index 0000000..c97b3d3 --- /dev/null +++ b/src/main/scala/sims/collision/Polygon.scala @@ -0,0 +1,32 @@ +/* _____ _ __ ________ ___ *\ +** / ___/(_) |/ / ___/ |__ \ Simple Mechanics Simulator 2 ** +** \__ \/ / /|_/ /\__ \ __/ / copyright (c) 2011 Jakob Odersky ** +** ___/ / / / / /___/ / / __/ ** +** /____/_/_/ /_//____/ /____/ ** +\* */ + +package sims.collision + +import sims.math._ + +/**Common properties of all polygons.*/ +trait Polygon extends Collidable { + + /**Returns positions of all vertices of this Polygon. Vertices are ordered counter-clockwise. + * @return position vectors of the vertices*/ + def vertices: Seq[Vector2D] + + /**Returns all sides of this polygon. The sides are ordered counter-clockwise, the first vertex of the side + * giving the side index.*/ + def sides: Seq[Segment] = for (i <- 0 until vertices.length) yield (new Segment(vertices(i), vertices((i + 1) % vertices.length))) + + /**Returns this polygon's axis aligned bounding box. + * @see collision.AABB*/ + override def aabb = { + val xs = vertices.view map (_.x) + val ys = vertices.view map (_.y) + new AABB(Vector2D(xs.min, ys.min), + Vector2D(xs.max, ys.max)) + } + +}
\ No newline at end of file |