diff --git a/build.sbt b/build.sbt index f9bd866..0505292 100644 --- a/build.sbt +++ b/build.sbt @@ -1,13 +1,15 @@ import xerial.sbt.Sonatype.GitHubHosting -val scalaParallelCollectionsVersion = "1.0.3" -val lwjglVersion = "3.2.3" -val scalaTestVersion = "3.2.9" +val scalaParallelCollectionsVersion = "1.0.4" +val lwjglVersion = "3.3.2" +val scalaTestVersion = "3.2.15" val logbackClassicVersion = "1.2.3" -val scalaLoggingVersion = "3.9.3" -val spireVersion = "0.17.0" +val scalaLoggingVersion = "3.9.5" +val spireVersion = "0.18.0" val scala213 = "2.13.6" +val scala3 = "3.2.2" +lazy val supportedScalaVersions = List(scala213, scala3) val scalaOptions = Seq( @@ -25,15 +27,16 @@ val scalaOptions = lazy val commonSettings = Seq( organization := "com.github.simerplaha", - version := "0.1.0", + version := "0.1.1", scalaVersion := scalaVersion.value, - scalaVersion in ThisBuild := scala213, - parallelExecution in ThisBuild := false, + ThisBuild/scalaVersion := scala3, + crossScalaVersions := supportedScalaVersions, + ThisBuild/parallelExecution := false, scalacOptions ++= scalaOptions ) val publishSettings = Seq[Setting[_]]( - crossScalaVersions := Seq(scala213), + crossScalaVersions := supportedScalaVersions, sonatypeProfileName := "com.github.simerplaha", publishMavenStyle := true, licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")), diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Box.scala b/graphics/src/main/scala/slack3d/graphics/shape/Box.scala index a8a23b8..2822334 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Box.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Box.scala @@ -42,7 +42,7 @@ object Box { ) val front = - back.setFlipNormal(false) + Vector3(0, 0, 2 * widths.z) + back.setFlipNormal(false) + Vector3[Double](0, 0, 2 * widths.z) val left = Plane( @@ -55,7 +55,7 @@ object Box { ) val right = - left.setFlipNormal(true) + Vector3(2 * widths.x, 0, 0) + left.setFlipNormal(true) + Vector3[Double](2 * widths.x, 0, 0) val top = Plane( @@ -68,7 +68,7 @@ object Box { ) val bottom = - top.setFlipNormal(true) + Vector3(0, -(2 * widths.y), 0) + top.setFlipNormal(true) + Vector3[Double](0, -(2 * widths.y), 0) new Box( back = back, @@ -115,7 +115,7 @@ case class Box(back: Plane, Array(back, front, left, right, top, bottom) def center() = - (back.center() + front.center() + left.center() + right.center() + top.center() + bottom.center()) / 6 + (back.center + front.center + left.center + right.center + top.center + bottom.center) / 6 def updateColour(colour: Colour): Box = mapPlanes(_.updateColour(colour)) diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Character.scala b/graphics/src/main/scala/slack3d/graphics/shape/Character.scala index 43e973d..47229bd 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Character.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Character.scala @@ -21,6 +21,7 @@ import slack3d.algebra.Vector3 import slack3d.graphics.colour.Colour import slack3d.graphics.shape.line.{Line, LineOrRay} + /** * NOTE: MAKE SURE ALL LINES HAVE 'showCoordinate' DISABLED OTHERWISE IT RESULTS IN NESTED LOOP CAUSING STACKOVERFLOW. */ @@ -35,7 +36,7 @@ object Character { characters.zipWithIndex.toArray map { case (character, index) => //creates the character at the origin and then scales to reduce to or increase size and then padds it - val translator = Vector3(index * xPadding, yPadding, 0) + position + val translator = Vector3[Double](index * xPadding, yPadding, 0) + position character match { case '1' => @@ -173,7 +174,7 @@ object Character { (line(colour) * scale) + translator case ' ' => - Character(lines = Array.empty, points = Array.empty) + Character(lines = Array.empty[Line], points = Array.empty[Point]) } } @@ -185,7 +186,7 @@ object Character { Line(fromX = 0, fromY = 0.5d, toX = -0.5d, toY = 0.25d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = -0.5d, fromY = -0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), ), - points = Array.empty + points = Array.empty[Point] ) def two(colour: Colour): Character = @@ -197,7 +198,7 @@ object Character { Line(fromX = -0.5d, fromY = 0, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = -0.5d, fromY = -0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def three(colour: Colour): Character = @@ -208,7 +209,7 @@ object Character { Line(fromX = 0.5d, fromY = -0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = 0.5d, fromY = 0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def four(colour: Colour): Character = @@ -218,7 +219,7 @@ object Character { Line(fromX = -0.5d, fromY = 0, toX = 0.5d, toY = 0d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = 0.5d, fromY = 0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), ), - points = Array.empty + points = Array.empty[Point] ) def five(colour: Colour): Character = @@ -231,13 +232,13 @@ object Character { Line(fromX = 0.5d, fromY = 0d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = 0.5d, fromY = -0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), ), - points = Array.empty + points = Array.empty[Point] ) def six(colour: Colour): Character = Character( five(colour).lines :+ Line(fromX = -0.5d, fromY = 0d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), - points = Array.empty + points = Array.empty[Point] ) def seven(colour: Colour): Character = @@ -246,13 +247,13 @@ object Character { Line(fromX = -0.5d, fromY = 0.5d, toX = 0.5d, toY = 0.5d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = 0.5d, fromY = 0.5d, toX = 0d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), ), - points = Array.empty + points = Array.empty[Point] ) def eight(colour: Colour): Character = Character( three(colour).lines :+ Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), - points = Array.empty + points = Array.empty[Point] ) def nine(colour: Colour): Character = @@ -263,7 +264,7 @@ object Character { Line(fromX = -0.5d, fromY = 0d, toX = -0.5d, toY = 0.5d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = 0.5d, fromY = 0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def zero(colour: Colour): Character = @@ -275,7 +276,7 @@ object Character { Line(fromX = -0.5d, fromY = -0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) // Line(fromX = -0.5d, fromY = 0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showCoordinate = false), //slash ), - points = Array.empty + points = Array.empty[Point] ) def comma(colour: Colour): Character = @@ -283,22 +284,22 @@ object Character { Array( Line(fromX = 0.0d, fromY = -0.50d, toX = -0.25d, toY = -1d, colour = colour, showCone = false, showVectorInfo = false), ), - points = Array.empty + points = Array.empty[Point] ) def dot(position: Vector3[Double], colour: Colour): Character = Character( - lines = Array.empty, + lines = Array.empty[Line], points = Array(Point(vector = position, colour = colour, showVectorInfo = false, size = 2)) ) def semiColon(position: Vector3[Double], colour: Colour): Character = Character( - lines = Array.empty, + lines = Array.empty[Line], points = Array( - Point(vector = position - Vector3(0d, 0.005d, 0), colour = colour, showVectorInfo = false, size = 2), - Point(vector = position + Vector3(0d, 0.006d, 0), colour = colour, showVectorInfo = false, size = 2) + Point(vector = position - Vector3[Double](0d, 0.005d, 0), colour = colour, showVectorInfo = false, size = 2), + Point(vector = position + Vector3[Double](0d, 0.006d, 0), colour = colour, showVectorInfo = false, size = 2) ) ) @@ -309,7 +310,7 @@ object Character { Line(fromX = -0.4d, fromY = 0.8d, toX = -0.4d, toY = -0.8d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = -0.4d, fromY = -0.8d, toX = 0.25d, toY = -0.8d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def rightBracket(colour: Colour): Character = @@ -319,7 +320,7 @@ object Character { Line(fromX = 0.25d, fromY = 0.8d, toX = 0.25d, toY = -0.8d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = -0.4d, fromY = -0.8d, toX = 0.25d, toY = -0.8d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def equalTo(colour: Colour): Character = @@ -328,7 +329,7 @@ object Character { Line(fromX = 0.5d, fromY = 0.2d, toX = -0.5d, toY = 0.2d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = 0.5d, fromY = -0.2d, toX = -0.5d, toY = -0.2d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def negative(colour: Colour): Character = @@ -336,7 +337,7 @@ object Character { Array( Line(fromX = 0.5d, fromY = 0d, toX = -0.5d, toY = 0d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def A(colour: Colour): Character = @@ -346,7 +347,7 @@ object Character { Line(fromX = 0, fromY = 0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = -0.3d, fromY = -0.1d, toX = 0.3d, toY = -0.1d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def B(colour: Colour): Character = @@ -363,7 +364,7 @@ object Character { Line(fromX = 0.3d, fromY = 0.5d, toX = 0.5d, toY = 0.3d, colour = colour, showCone = false, showVectorInfo = false), //slit up Line(fromX = 0.3d, fromY = -0.5d, toX = 0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false) //slit down ), - points = Array.empty + points = Array.empty[Point] ) def C(colour: Colour): Character = @@ -377,7 +378,7 @@ object Character { Line(fromX = 0.3d, fromY = -0.5d, toX = 0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false), //bottom to right Line(fromX = -0.3d, fromY = -0.5d, toX = 0.3d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), ), - points = Array.empty + points = Array.empty[Point] ) def D(colour: Colour): Character = @@ -390,7 +391,7 @@ object Character { Line(fromX = 0.3d, fromY = -0.5d, toX = 0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false), //smaller cut bottom Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) //left ), - points = Array.empty + points = Array.empty[Point] ) def E(colour: Colour): Character = @@ -401,7 +402,7 @@ object Character { Line(fromX = 0.5d, fromY = -0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def F(colour: Colour): Character = @@ -411,7 +412,7 @@ object Character { Line(fromX = 0.5d, fromY = 0d, toX = -0.5d, toY = 0d, colour = colour, showCone = false, showVectorInfo = false), Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) ), - points = Array.empty + points = Array.empty[Point] ) def G(colour: Colour): Character = @@ -427,7 +428,7 @@ object Character { Line(fromX = 0.5d, fromY = 0d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //right Line(fromX = -0.5d, fromY = 0.3d, toX = -0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false) //left ), - points = Array.empty + points = Array.empty[Point] ) def H(colour: Colour): Character = @@ -437,7 +438,7 @@ object Character { Line(fromX = 0.5d, fromY = 0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //right Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) //left ), - points = Array.empty + points = Array.empty[Point] ) def I(colour: Colour): Character = @@ -447,7 +448,7 @@ object Character { Line(fromX = 0d, fromY = 0.5d, toX = 0d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //mid Line(fromX = 0.5d, fromY = -0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //bottom ), - points = Array.empty + points = Array.empty[Point] ) def J(colour: Colour): Character = @@ -458,7 +459,7 @@ object Character { Line(fromX = 0.1d, fromY = 0.5d, toX = 0.1d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //mid Line(fromX = -0.5d, fromY = 0d, toX = -0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false) //left ), - points = Array.empty + points = Array.empty[Point] ) def K(colour: Colour): Character = @@ -468,7 +469,7 @@ object Character { Line(fromX = -0.5d, fromY = 0d, toX = 0.5d, toY = 0.5d, colour = colour, showCone = false, showVectorInfo = false), //upper Line(fromX = -0.5d, fromY = 0d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //lower ), - points = Array.empty + points = Array.empty[Point] ) def L(colour: Colour): Character = @@ -477,7 +478,7 @@ object Character { Line(fromX = 0.5d, fromY = -0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //bottom Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) //left ), - points = Array.empty + points = Array.empty[Point] ) def M(colour: Colour): Character = @@ -488,7 +489,7 @@ object Character { Line(fromX = -0.5d, fromY = 0.5d, toX = 0d, toY = 0d, colour = colour, showCone = false, showVectorInfo = false), //mid left Line(fromX = 0.5d, fromY = 0.5d, toX = 0d, toY = 0d, colour = colour, showCone = false, showVectorInfo = false), //mid right ), - points = Array.empty + points = Array.empty[Point] ) def N(colour: Colour): Character = @@ -498,7 +499,7 @@ object Character { Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //left Line(fromX = -0.5d, fromY = 0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //bottom ), - points = Array.empty + points = Array.empty[Point] ) def O(colour: Colour): Character = @@ -513,7 +514,7 @@ object Character { Line(fromX = -0.5d, fromY = 0.3d, toX = -0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false), //left Line(fromX = 0.3d, fromY = -0.5d, toX = 0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false) //bottom to right ), - points = Array.empty + points = Array.empty[Point] ) def P(colour: Colour): Character = @@ -526,19 +527,19 @@ object Character { Line(fromX = 0.5d, fromY = 0.3d, toX = 0.5d, toY = 0.2d, colour = colour, showCone = false, showVectorInfo = false), //right Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) //left ), - points = Array.empty + points = Array.empty[Point] ) def Q(colour: Colour): Character = Character( O(colour).lines :+ Line(fromX = 0.2d, fromY = -0.2d, toX = 0.7d, toY = -0.7d, colour = colour, showCone = false, showVectorInfo = false), //comma - points = Array.empty + points = Array.empty[Point] ) def R(colour: Colour): Character = Character( P(colour).lines :+ Line(fromX = 0d, fromY = 0d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //bottom cut - points = Array.empty + points = Array.empty[Point] ) def S(colour: Colour): Character = @@ -556,7 +557,7 @@ object Character { Line(fromX = -0.5d, fromY = 0.1d, toX = -0.5d, toY = 0.4d, colour = colour, showCone = false, showVectorInfo = false), //left Line(fromX = 0.5d, fromY = -0.4d, toX = 0.3d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //right to bottom ), - points = Array.empty + points = Array.empty[Point] ) def T(colour: Colour): Character = @@ -565,7 +566,7 @@ object Character { Line(fromX = 0.5d, fromY = 0.5d, toX = -0.5d, toY = 0.5d, colour = colour, showCone = false, showVectorInfo = false), //top Line(fromX = 0d, fromY = 0.5d, toX = 0d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //mid ), - points = Array.empty + points = Array.empty[Point] ) def U(colour: Colour): Character = @@ -577,7 +578,7 @@ object Character { Line(fromX = -0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false), //left Line(fromX = 0.3d, fromY = -0.5d, toX = 0.5d, toY = -0.3d, colour = colour, showCone = false, showVectorInfo = false) //bottom to right ), - points = Array.empty + points = Array.empty[Point] ) def V(colour: Colour): Character = @@ -586,7 +587,7 @@ object Character { Line(fromX = 0.5d, fromY = 0.5d, toX = 0d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //right Line(fromX = -0.5d, fromY = 0.5d, toX = 0d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false) //left ), - points = Array.empty + points = Array.empty[Point] ) def W(colour: Colour): Character = @@ -597,7 +598,7 @@ object Character { Line(fromX = 0.5d, fromY = 0.5d, toX = 0.25d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //right Line(fromX = 0.25d, fromY = -0.5d, toX = 0d, toY = 0d, colour = colour, showCone = false, showVectorInfo = false), //right to mid ), - points = Array.empty + points = Array.empty[Point] ) def X(colour: Colour): Character = @@ -606,7 +607,7 @@ object Character { Line(fromX = -0.5d, fromY = 0.5d, toX = 0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //left to right Line(fromX = 0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //right to left ), - points = Array.empty + points = Array.empty[Point] ) def Y(colour: Colour): Character = @@ -616,7 +617,7 @@ object Character { Line(fromX = 0.5d, fromY = 0.5d, toX = 0d, toY = 0d, colour = colour, showCone = false, showVectorInfo = false), //top Line(fromX = 0d, fromY = 0d, toX = 0d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //top ), - points = Array.empty + points = Array.empty[Point] ) def Z(colour: Colour): Character = @@ -626,7 +627,7 @@ object Character { Line(fromX = 0.5d, fromY = -0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //bottom Line(fromX = 0.5d, fromY = 0.5d, toX = -0.5d, toY = -0.5d, colour = colour, showCone = false, showVectorInfo = false), //right to left ), - points = Array.empty + points = Array.empty[Point] ) def line(colour: Colour): Character = @@ -634,7 +635,7 @@ object Character { Array( Line(fromX = 0d, fromY = 1d, toX = 0d, toY = -1d, colour = colour, showCone = false, showVectorInfo = false), //mid ), - points = Array.empty + points = Array.empty[Point] ) } diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Circle.scala b/graphics/src/main/scala/slack3d/graphics/shape/Circle.scala index 75a059f..4f69003 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Circle.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Circle.scala @@ -76,7 +76,7 @@ object Circle { Matrix3.rotatorY[Double](Math.toRadians(90d)) * Circle.xy(colour, radius, triangles) } -case class Circle private(center: Vector3[Double], +case class Circle (center: Vector3[Double], triangles: Array[Triangle], flipNormal: Boolean) extends NormalisableShape { diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Cylinder.scala b/graphics/src/main/scala/slack3d/graphics/shape/Cylinder.scala index 4fc901f..1be32cf 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Cylinder.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Cylinder.scala @@ -29,8 +29,8 @@ object Cylinder { val unitCircle: Circle = Circle.xz(colour, radius, sectors) - val head = unitCircle + Vector3(0d, 0.5d, 0.0d) - val base = unitCircle + Vector3(0d, -0.5d, 0.0d) + val head = unitCircle + Vector3[Double](0d, 0.5d, 0.0d) + val base = unitCircle + Vector3[Double](0d, -0.5d, 0.0d) val planes = head.triangles.zip(base.triangles) map { diff --git a/graphics/src/main/scala/slack3d/graphics/shape/NormalisableShape.scala b/graphics/src/main/scala/slack3d/graphics/shape/NormalisableShape.scala index a594dc3..aaaa8ca 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/NormalisableShape.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/NormalisableShape.scala @@ -25,7 +25,7 @@ trait NormalisableShape extends Shape { def normal(): Vector3[Double] - def center(): Vector3[Double] + def center: Vector3[Double] def normalLine(colour: Colour, text: String) = @@ -45,7 +45,7 @@ trait NormalisableShape extends Shape { def normalLineFromCentre(colour: Colour = Colour.next(), text: Option[String] = None, showVectorInfo: Boolean = true) = { - val center = this.center() + val center = this.center val perpendicular = this.normal() + center Line( from = center, diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Plane.scala b/graphics/src/main/scala/slack3d/graphics/shape/Plane.scala index ae899f0..bc5c3c3 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Plane.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Plane.scala @@ -194,8 +194,8 @@ case class Plane(triangleA: Triangle, override def normal(): Vector3[Double] = triangleA.normal() - def center(): Vector3[Double] = - (triangleA.center() + triangleB.center()) / 2d + def center: Vector3[Double] = + (triangleA.center + triangleB.center) / 2d def distance(): Double = this.normal() dot triangleB.a diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Point.scala b/graphics/src/main/scala/slack3d/graphics/shape/Point.scala index bcd91ff..5e72049 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Point.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Point.scala @@ -25,7 +25,7 @@ object Point { val DEFAULT_POINT_SIZE = 6f - implicit val lexOrdering = + implicit val lexOrdering: Ordering[Point] = new Ordering[Point] { override def compare(left: Point, right: Point): Int = { val xCompare = left.vector.x compareTo right.vector.x @@ -197,7 +197,7 @@ object Point { } } -case class Point private(vector: Vector3[Double], +case class Point (vector: Vector3[Double], colour: Colour, size: Float, text: Option[Text], diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Pyramid.scala b/graphics/src/main/scala/slack3d/graphics/shape/Pyramid.scala index 7565b10..12608e8 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Pyramid.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Pyramid.scala @@ -104,7 +104,7 @@ case class Pyramid private(head: Point, head.vector +: (left.vectors() ++ front.vectors() ++ right.vectors() ++ back.vectors() ++ base.vectors()) def height() = - (head.vector - base.center()).length() + (head.vector - base.center).length() override def map(f: Vector3[Double] => Vector3[Double]): Pyramid = Pyramid( diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Shape.scala b/graphics/src/main/scala/slack3d/graphics/shape/Shape.scala index 2e1665b..9d7a199 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Shape.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Shape.scala @@ -20,6 +20,7 @@ package slack3d.graphics.shape import slack3d.algebra.{Isometry3, Matrix3, Vector3} import slack3d.graphics.window.Window import spire.implicits._ +import slack3d.graphics.shape.Shape._ object Shape { @@ -35,7 +36,7 @@ object Shape { @inline def *[S <: Shape](shape: S): S = shape.map { vec => - isometry.isometries().foldLeft(vec) { + isometry.isometries.foldLeft(vec) { (vector, isometry) => (isometry.rotation * vector) + isometry.translation } @@ -123,7 +124,8 @@ trait Shape extends Meshable { } else { val rotationX = Matrix3.rotatorX[Double](Math.toRadians(-vector.y)) val rotationZ = Matrix3.rotatorZ[Double](Math.toRadians(-vector.x)) - (rotationX * rotationZ * this).asInstanceOf[Self] + val r = (rotationX * rotationZ) + (r * this).asInstanceOf[Self] } case None => diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Tetrahedron.scala b/graphics/src/main/scala/slack3d/graphics/shape/Tetrahedron.scala index 5cf27db..2f311ae 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Tetrahedron.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Tetrahedron.scala @@ -78,7 +78,7 @@ object Tetrahedron { } } -case class Tetrahedron private(point: Point, +case class Tetrahedron (point: Point, face1: Triangle, face2: Triangle, face3: Triangle, diff --git a/graphics/src/main/scala/slack3d/graphics/shape/Triangle.scala b/graphics/src/main/scala/slack3d/graphics/shape/Triangle.scala index 305a6d8..ac58ed6 100644 --- a/graphics/src/main/scala/slack3d/graphics/shape/Triangle.scala +++ b/graphics/src/main/scala/slack3d/graphics/shape/Triangle.scala @@ -94,7 +94,7 @@ case class Triangle(a: Vector3[Double], def vectors() = Array(a, b, c) - def center(): Vector3[Double] = + def center: Vector3[Double] = (a + b + c) / 3 override def normal(): Vector3[Double] = diff --git a/linear-algebra/src/main/scala/slack3d/algebra/Isometry3.scala b/linear-algebra/src/main/scala/slack3d/algebra/Isometry3.scala index 6ff6725..eab1119 100644 --- a/linear-algebra/src/main/scala/slack3d/algebra/Isometry3.scala +++ b/linear-algebra/src/main/scala/slack3d/algebra/Isometry3.scala @@ -24,7 +24,7 @@ import scala.reflect.ClassTag sealed trait Isometry3[A] { - def isometries(): Array[Isometry3.Single[A]] + def isometries: Array[Isometry3.Single[A]] def *(vector: Vector3[A]): Vector3[A] @@ -56,14 +56,15 @@ object Isometry3 { def *(vector: Vector3[A]): Vector3[A] = (rotation * vector) + translation - override def isometries(): Array[Single[A]] = + override def isometries: Array[Single[A]] = Array(this) override def *(isometry: Isometry3[A]): Isometry3.Many[A] = - Many(this +: isometry.isometries()) + Many(this +: isometry.isometries) } case class Many[A] private(isometries: Array[Isometry3.Single[A]]) extends Isometry3[A] { + override def *(vector: Vector3[A]): Vector3[A] = isometries.foldLeft(vector) { case (vector, iso) => @@ -71,6 +72,11 @@ object Isometry3 { } override def *(isometry: Isometry3[A]): Many[A] = - Many(this.isometries ++ isometry.isometries()) + Many(this.isometries ++ isometry.isometries) + } + + object Many { + def apply[A](isometries: Array[Isometry3.Single[A]]): Many[A] = + new Many[A](isometries) } } diff --git a/linear-algebra/src/main/scala/slack3d/algebra/Matrix2.scala b/linear-algebra/src/main/scala/slack3d/algebra/Matrix2.scala index 3cac0ad..74272c6 100644 --- a/linear-algebra/src/main/scala/slack3d/algebra/Matrix2.scala +++ b/linear-algebra/src/main/scala/slack3d/algebra/Matrix2.scala @@ -166,7 +166,7 @@ case class Matrix2[A: ClassTag](_00: A, _01: A, invert().transpose() def negate() = - this * -1 + this * num.fromDouble(-1.0) //@formatter:off def lerp(other: Matrix2[A], factor: A) = diff --git a/linear-algebra/src/main/scala/slack3d/algebra/Matrix3.scala b/linear-algebra/src/main/scala/slack3d/algebra/Matrix3.scala index fe11fd4..4cd9cfc 100644 --- a/linear-algebra/src/main/scala/slack3d/algebra/Matrix3.scala +++ b/linear-algebra/src/main/scala/slack3d/algebra/Matrix3.scala @@ -156,7 +156,7 @@ object Matrix3 { ) val translate = - Vector3(0, 0, _23) + Vector3[Double](0, 0, _23) Isometry3( rotation = rotate, diff --git a/linear-algebra/src/main/scala/slack3d/algebra/Vector2.scala b/linear-algebra/src/main/scala/slack3d/algebra/Vector2.scala index ea8564b..89fb17f 100644 --- a/linear-algebra/src/main/scala/slack3d/algebra/Vector2.scala +++ b/linear-algebra/src/main/scala/slack3d/algebra/Vector2.scala @@ -27,10 +27,10 @@ import scala.reflect.ClassTag object Vector2 { def origin[A: ClassTag : Numeric](): Vector2[A] = - Vector2[A](0, 0) + Vector2[A](Numeric[A].fromDouble(0.0), Numeric[A].fromDouble(0.0)) def one[A: ClassTag : Numeric](): Vector2[A] = - Vector2[A](1, 1) + Vector2[A](Numeric[A].fromDouble(1.0),Numeric[A].fromDouble(1.0)) } diff --git a/linear-algebra/src/main/scala/slack3d/algebra/Vector3.scala b/linear-algebra/src/main/scala/slack3d/algebra/Vector3.scala index 4af20f5..493a949 100644 --- a/linear-algebra/src/main/scala/slack3d/algebra/Vector3.scala +++ b/linear-algebra/src/main/scala/slack3d/algebra/Vector3.scala @@ -235,13 +235,13 @@ case class Vector3[A: ClassTag](x: A, trig.toDegrees(angleRadian(vec)) def reflect(normal: Vector3[A]): Vector3[A] = - (project(normal) * 2) - this + (project(normal) * Numeric[A].fromDouble(2)) - this /** * Reflection how it is defined in OpenGL */ def reflectOpenGL(normal: Vector3[A]): Vector3[A] = - this - (normal * ((2: A) * normal.dot(this))) + this - (normal * ((Numeric[A].fromDouble(2.0)) * normal.dot(this))) def project(normal: Vector3[A]): Vector3[A] = normal * this.dot(normal) @@ -256,10 +256,10 @@ case class Vector3[A: ClassTag](x: A, this dot this def length(): A = - sqrt(this.lengthSquared()) + spire.math.sqrt(this.lengthSquared()) def negate(): Vector3[A] = - this * -1 + this * Numeric[A].fromDouble(-1) def minLength(that: Vector3[A]): Vector3[A] = if (this.lengthSquared() < that.lengthSquared()) @@ -394,9 +394,9 @@ case class Vector3[A: ClassTag](x: A, def toDouble(): Vector3[Double] = Vector3( - x.toDouble(), - y.toDouble(), - z.toDouble() + x.toDouble, + y.toDouble, + z.toDouble ) def toTuple3Or2String(): String = diff --git a/project/build.properties b/project/build.properties index 215ddd2..e2142ad 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 1.5.5 \ No newline at end of file +sbt.version = 1.8.2 \ No newline at end of file diff --git a/project/plugin.sbt b/project/plugin.sbt index 403495c..53ec3af 100644 --- a/project/plugin.sbt +++ b/project/plugin.sbt @@ -1,2 +1,2 @@ -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.20") +addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") \ No newline at end of file