summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2009-12-20 17:53:45 +0000
committerJakob Odersky <jodersky@gmail.com>2009-12-20 17:53:45 +0000
commite87fcc40f9a2e8624d3260abf8180596de79b152 (patch)
treea3052eb7b657099e2bd616ce74b903f6250527e5
parent66d338aec5d632927fa561a68310c8931938e9e0 (diff)
downloadsims-e87fcc40f9a2e8624d3260abf8180596de79b152.tar.gz
sims-e87fcc40f9a2e8624d3260abf8180596de79b152.tar.bz2
sims-e87fcc40f9a2e8624d3260abf8180596de79b152.zip
Made code fully compatible with scala 2.8.
-rw-r--r--src/graphyx/Graphyx.scala1
-rw-r--r--src/graphyx/graphics/GraphicalAABB.scala2
-rw-r--r--src/graphyx/graphics/GraphicalCircle.scala2
-rw-r--r--src/graphyx/graphics/GraphicalRectangle.scala2
-rw-r--r--src/graphyx/graphics/GraphicalRegularPolygon.scala2
-rw-r--r--src/graphyx/graphics/Parser.scala20
-rw-r--r--src/graphyx/gui/InfoPanel.scala6
-rw-r--r--src/graphyx/gui/MainFrame.scala3
-rw-r--r--src/graphyx/gui/WorldPanel.scala2
-rw-r--r--src/graphyx/tests/Cannon.scala2
-rw-r--r--src/sims/collision/GridDetector.scala10
-rw-r--r--src/sims/collision/Pair.scala7
-rw-r--r--src/sims/dynamics/joints/ForceJoint.scala2
-rw-r--r--src/sims/geometry/ConvexPolygon.scala4
14 files changed, 35 insertions, 30 deletions
diff --git a/src/graphyx/Graphyx.scala b/src/graphyx/Graphyx.scala
index 192b897..5720566 100644
--- a/src/graphyx/Graphyx.scala
+++ b/src/graphyx/Graphyx.scala
@@ -13,7 +13,6 @@ import sims.geometry._
import sims.dynamics._
object Graphyx{
-
val tests: List[graphyx.tests.Test] = List(
CompositeShape,
Joints1,
diff --git a/src/graphyx/graphics/GraphicalAABB.scala b/src/graphyx/graphics/GraphicalAABB.scala
index 3d8999c..cb3694b 100644
--- a/src/graphyx/graphics/GraphicalAABB.scala
+++ b/src/graphyx/graphics/GraphicalAABB.scala
@@ -7,7 +7,7 @@
package graphyx.graphics
import sims.collision._
-case class GraphicalAABB(real: AABB) extends AABB(real.minVertex, real.maxVertex) with GraphicalObject {
+class GraphicalAABB(val real: AABB) extends AABB(real.minVertex, real.maxVertex) with GraphicalObject {
override def draw() = {
g.setColor(java.awt.Color.BLACK)
g.drawRect((minVertex.x * scale * ppm).toInt,
diff --git a/src/graphyx/graphics/GraphicalCircle.scala b/src/graphyx/graphics/GraphicalCircle.scala
index 31f057d..ffbd7a6 100644
--- a/src/graphyx/graphics/GraphicalCircle.scala
+++ b/src/graphyx/graphics/GraphicalCircle.scala
@@ -9,7 +9,7 @@ package graphyx.graphics
import sims._
import geometry._
import dynamics._
-case class GraphicalCircle(real: Circle) extends Circle(real.radius, real.density) with GraphicalShape{
+class GraphicalCircle(val real: Circle) extends Circle(real.radius, real.density) with GraphicalShape{
override def draw() = {
//val b = Math.min(density / 100 * 255, 255)
//g.setColor(new java.awt.Color(0,0,255, b.toInt))
diff --git a/src/graphyx/graphics/GraphicalRectangle.scala b/src/graphyx/graphics/GraphicalRectangle.scala
index ae65c5e..05dfa76 100644
--- a/src/graphyx/graphics/GraphicalRectangle.scala
+++ b/src/graphyx/graphics/GraphicalRectangle.scala
@@ -8,7 +8,7 @@ package graphyx.graphics
import sims._
import sims.dynamics._
-case class GraphicalRectangle(real: Rectangle) extends Rectangle(real.halfWidth, real.halfHeight, real.density) with GraphicalShape {
+class GraphicalRectangle(val real: Rectangle) extends Rectangle(real.halfWidth, real.halfHeight, real.density) with GraphicalShape {
override def draw() = {
g.setColor(java.awt.Color.red)
fillPolygon(vertices)
diff --git a/src/graphyx/graphics/GraphicalRegularPolygon.scala b/src/graphyx/graphics/GraphicalRegularPolygon.scala
index a3906c3..fff8a9e 100644
--- a/src/graphyx/graphics/GraphicalRegularPolygon.scala
+++ b/src/graphyx/graphics/GraphicalRegularPolygon.scala
@@ -9,7 +9,7 @@ package graphyx.graphics
import sims._
import geometry._
import dynamics._
-case class GraphicalRegularPolygon(real: RegularPolygon) extends RegularPolygon(real.n, real.radius, real.density) with GraphicalShape{
+class GraphicalRegularPolygon(val real: RegularPolygon) extends RegularPolygon(real.n, real.radius, real.density) with GraphicalShape{
override def draw() = {
g.setColor(java.awt.Color.orange)
fillPolygon(vertices)
diff --git a/src/graphyx/graphics/Parser.scala b/src/graphyx/graphics/Parser.scala
index 9468d16..785d985 100644
--- a/src/graphyx/graphics/Parser.scala
+++ b/src/graphyx/graphics/Parser.scala
@@ -14,22 +14,22 @@ object Parser {
val throwOnUnknown = false
def toGraphical(real: Shape) = real match {
- case c: Circle => GraphicalCircle(c)
- case r: Rectangle => GraphicalRectangle(r)
- case p: RegularPolygon => GraphicalRegularPolygon(p)
+ case c: Circle => new GraphicalCircle(c)
+ case r: Rectangle => new GraphicalRectangle(r)
+ case p: RegularPolygon => new GraphicalRegularPolygon(p)
case _ => throw new IllegalArgumentException("Cannot cast '" + real.getClass + "' to a graphical object.")
}
def toGraphical(real: Joint) = real match {
- case j: DistanceJoint => GraphicalDistanceJoint(j)
- case j: SpringJoint => GraphicalSpringJoint(j)
- case j: RevoluteJoint => GraphicalRevoluteJoint(j)
+ case j: DistanceJoint => new GraphicalDistanceJoint(j)
+ case j: SpringJoint => new GraphicalSpringJoint(j)
+ case j: RevoluteJoint => new GraphicalRevoluteJoint(j)
case j: Joint => if (!throwOnUnknown) new GraphicalJoint{override val real = j; def draw = ()}
else throw new IllegalArgumentException("Cannot cast '" + real.getClass + "' to a graphical object.")
}
- def toGraphical(real: Collision) = GraphicalCollision(real)
- def toGraphical(real: Pair) = GraphicalPair(real)
- def toGraphical(real: AABB) = GraphicalAABB(real)
- def toGraphical(real: Body) = GraphicalBody(real)
+ def toGraphical(real: Collision) = new GraphicalCollision(real)
+ def toGraphical(real: Pair) = new GraphicalPair(real)
+ def toGraphical(real: AABB) = new GraphicalAABB(real)
+ def toGraphical(real: Body) = new GraphicalBody(real)
}
diff --git a/src/graphyx/gui/InfoPanel.scala b/src/graphyx/gui/InfoPanel.scala
index 6e58ba3..d9dad43 100644
--- a/src/graphyx/gui/InfoPanel.scala
+++ b/src/graphyx/gui/InfoPanel.scala
@@ -7,9 +7,11 @@
package graphyx.gui
import scala.swing._
+import scala.swing._
+
class InfoPanel(container: Container) extends BoxPanel(Orientation.Vertical){
- preferredSize = (200, 50)
-
+ preferredSize = new java.awt.Dimension(200, 50)
+
val out = new TextArea
out.editable = false
contents += out
diff --git a/src/graphyx/gui/MainFrame.scala b/src/graphyx/gui/MainFrame.scala
index 6b1f2fe..4fdc9a2 100644
--- a/src/graphyx/gui/MainFrame.scala
+++ b/src/graphyx/gui/MainFrame.scala
@@ -13,7 +13,8 @@ import scala.swing._
class MainFrame(container: Container) extends Frame{
super.background = java.awt.Color.WHITE
title = "graphyx"
- preferredSize = (1000,800)
+ preferredSize = new java.awt.Dimension(1000,800)
+
reactions += {
case event.WindowClosing(w) => Graphyx.exit()
}
diff --git a/src/graphyx/gui/WorldPanel.scala b/src/graphyx/gui/WorldPanel.scala
index 7f9fbee..ad14726 100644
--- a/src/graphyx/gui/WorldPanel.scala
+++ b/src/graphyx/gui/WorldPanel.scala
@@ -128,7 +128,7 @@ class WorldPanel(container: Container) extends BoxPanel(Orientation.Vertical){
grabbedBody = None
}
- listenTo(Mouse.clicks, Mouse.moves, Mouse.wheel)
+ listenTo(mouse.clicks, mouse.moves, mouse.wheel)
reactions += {
case MousePressed(c,p,x,y,b) => {
mousePressed = true; startPoint = p; endPoint = p
diff --git a/src/graphyx/tests/Cannon.scala b/src/graphyx/tests/Cannon.scala
index 7738103..01ce4e5 100644
--- a/src/graphyx/tests/Cannon.scala
+++ b/src/graphyx/tests/Cannon.scala
@@ -35,7 +35,7 @@ object Cannon extends Test{
) {fixed = (i == 0)}
}
world += cannon
- world ++= List.flatten(stack)
+ world ++= stack.flatten
}
diff --git a/src/sims/collision/GridDetector.scala b/src/sims/collision/GridDetector.scala
index abc40f2..9a71c6d 100644
--- a/src/sims/collision/GridDetector.scala
+++ b/src/sims/collision/GridDetector.scala
@@ -12,14 +12,14 @@ import scala.collection._
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.HashMap
-/**A conrete implementation of <code>Detector</code>. <code>GridDetector</code> divides the world into a grid
+/**A concrete implementation of <code>Detector</code>. <code>GridDetector</code> divides the world into a grid
* for faster collision detection.*/
class GridDetector(override val world: World) extends Detector {
/**Array of collision detection methods. These methods return <code>true</code> if two shapes are colliding.*/
val detectionMethods = new ArrayBuffer[PartialFunction[(Shape, Shape), Boolean]]
detectionMethods += {
- case (c1: Circle, c2: Circle) => { //Kollision wenn Distanz <= Summe der Radien
+ case (c1: Circle, c2: Circle) => { //collision if distance <= sum of radiuses
val d = (c1.pos - c2.pos).length
val rSum = c1.radius + c2.radius
d - rSum <= 0
@@ -31,12 +31,12 @@ class GridDetector(override val world: World) extends Detector {
axes.forall((a: Vector2D) => p1.project(a) overlaps p2.project(a))
}
- case (p: ConvexPolygon, c: Circle) => { //Distanz von Zentrum zu Seiten oder Eckpunkten
+ case (p: ConvexPolygon, c: Circle) => { //distance form center to sides or vertices
val distances = for (s <- p.sides) yield (s distance c.pos)
distances.exists(_ - c.radius <= 0) || (p contains c.pos)
}
- case (c: Circle, p: ConvexPolygon) => { //Distanz von Zentrum zu Seiten oder Eckpunkten
+ case (c: Circle, p: ConvexPolygon) => { //distance form center to sides or vertices
val distances = for (s <- p.sides) yield (s distance c.pos)
distances.exists(_ - c.radius <= 0) || (p contains c.pos)
}
@@ -97,7 +97,7 @@ class GridDetector(override val world: World) extends Detector {
}
for(s <- world.shapes) addToGrid(s)
var ps: List[Pair] = Nil
- for(cell <- grid.values) {
+ for(cell <- grid.valuesIterator) {
ps = ps ::: (for (s1: Shape <- cell; s2: Shape <- cell;
if (s1 ne s2);
if (s1.body ne s2.body);
diff --git a/src/sims/collision/Pair.scala b/src/sims/collision/Pair.scala
index e4ae947..a01fb00 100644
--- a/src/sims/collision/Pair.scala
+++ b/src/sims/collision/Pair.scala
@@ -9,8 +9,7 @@ package sims.collision
import sims.dynamics._
/**Pair of shapes.*/
-case class Pair(s1: Shape, s2: Shape) extends Tuple2(s1, s2){
- def this(t: Tuple2[Shape, Shape]) = this(t._1, t._2)
+case class Pair(s1: Shape, s2: Shape){
override def equals(other: Any) = { //overriden to prevent removal during "GridDetector.getPairs"
other match {
@@ -19,3 +18,7 @@ case class Pair(s1: Shape, s2: Shape) extends Tuple2(s1, s2){
}
}
}
+
+object Pair {
+ implicit def pair2Tuple(x: Pair) = (x.s1, x.s2)
+}
diff --git a/src/sims/dynamics/joints/ForceJoint.scala b/src/sims/dynamics/joints/ForceJoint.scala
index 1eed850..2074ee4 100644
--- a/src/sims/dynamics/joints/ForceJoint.scala
+++ b/src/sims/dynamics/joints/ForceJoint.scala
@@ -9,6 +9,6 @@ package sims.dynamics.joints
/**A joint which can apply a force to its anchor bodies, thus adding or removing energy to the system.*/
trait ForceJoint {
- /**Applies a force on the achor bodies.*/
+ /**Applies a force on the anchor bodies.*/
def applyForce(): Unit
}
diff --git a/src/sims/geometry/ConvexPolygon.scala b/src/sims/geometry/ConvexPolygon.scala
index cb4a429..0b05aaa 100644
--- a/src/sims/geometry/ConvexPolygon.scala
+++ b/src/sims/geometry/ConvexPolygon.scala
@@ -36,8 +36,8 @@ trait ConvexPolygon {
def AABB = {
val xs = vertices map (_.x)
val ys = vertices map (_.y)
- new AABB(Vector2D(Iterable.min(xs), Iterable.min(ys)),
- Vector2D(Iterable.max(xs), Iterable.max(ys)))
+ new AABB(Vector2D(xs.min, ys.min),
+ Vector2D(xs.max, ys.max))
}
/**Checks if the point <code>point</code> is contained in this polygon.