blob: c97b3d3b4918c3fe35ec3ab348d6db52faf4790b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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))
}
}
|