Packages

  • package root
    Definition Classes
    root
  • package o1

    O1Library is a toolkit designed for the course Programming 1 (a.k.a. O1) at Aalto University.

    O1Library is a toolkit designed for the course Programming 1 (a.k.a. O1) at Aalto University. It contains an assortment of tools; most prominently, it provides a framework for simple graphical programming and utilities for playing sound.

    This is the front page of O1Library’s documentation. However, this is probably not the best place to start learning about O1Library as a student. That’s because the relevant content of this library is introduced bit by bit in the chapters of O1’s custom ebook alongside the associated programming concepts and assignments.

    You may still find this documentation useful as a reference. You can also find some optional content here that you may wish to try.

    This front page lists the content available in the top-level package called simply o1. These tools are available with the simple command import o1._ in your Scala programs. Some of them you’ll use a lot; some of them you won’t necessarily need at all.

    The tools listed here are actually implemented in a number of subpackages (o1.gui, o1.sound, etc.); what you see here are just “shortcut aliases” to those actual implementations. The aliases are here to make that convenient import command work and to provide you with this list of links to some of the more commonly used tools in O1Library. The subpackages also contain additional content not listed here.

    O1Library has been developed by Aleksi Lukkarinen and Juha Sorva. Several of the key components in o1.gui and o1.world are built upon Aleksi’s Scala Media Computation Library. Some parts of O1Library draw inspiration from the “teachpacks” of the Racket programming language.

    We are grateful to Riku Autio, Joonatan Honkamaa, Juhani Numminen, Leo Varis, Veera Kahva, and anonymous students for bug reports and fixes. We thank Otto Seppälä for helpful discussions.

    Definition Classes
    root
  • package world

    This package contains tools for locations and movement in two-dimensional space.

    This package contains tools for locations and movement in two-dimensional space.

    The tools in this package have aliases in the top-level package o1, so they are accessible to students simply via import o1._.

    The subpackage o1.world.objects contains additional tools for representing entities that reside within two-dimensional spaces.

    Definition Classes
    o1
  • package objects

    This package contains tools for representing objects that exist in two-dimensional space.

    This package contains tools for representing objects that exist in two-dimensional space. In particular, it defines:

    • the Anchor type: an anchor is the point where an object connects to its environment; and
    • a number of traits (HasPos, HasVelocity, etc.) the classes of an application can mix in to gain access to various convenience methods.

    NOTE TO STUDENTS: In this course, you don't need to understand how this package works or can be used. That being said, some students may wish to experiment with some of its contents. Many of the traits in this package have aliases in the top-level package o1, so they are accessible to students simply via import o1._.

    Definition Classes
    world
  • Bounds
  • Direction
  • Pos
  • Velocity

final case class Pos(x: Double, y: Double) extends Product with Serializable

Each instance of this class represents a location on a two-dimensional plane. A Pos object is essentially a pair of two coordinates, x and y. Pos objects are immutable.

This class has an alias in the top-level package o1, so it’s accessible to students simply via import o1._.

x

the x coordinate of the Pos

y

the y coordinate of the Pos

Linear Supertypes
Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Pos
  2. Serializable
  3. Product
  4. Equals
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Pos(x: Double, y: Double)

    x

    the x coordinate of the Pos

    y

    the y coordinate of the Pos

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def *(factor: Double): Pos

    Returns a Pos whose two coordinates are obtained by multiplying this one’s x and y by the given factor.

    Returns a Pos whose two coordinates are obtained by multiplying this one’s x and y by the given factor. For instance, (2,-3) multiplied by 10 is (20,-30). The expressions myPos * n and myPos.multiply(n) are equivalent.

    Annotations
    @inline()
  4. def +(another: Pos): Pos

    Adds the x and y of the given Pos to the x and y of this Pos, respectively.

    Adds the x and y of the given Pos to the x and y of this Pos, respectively. Returns the resulting Pos. The expressions pos1 + pos2, pos1.add(pos2), and pos1.offset(pos2) are equivalent.

    Annotations
    @inline()
  5. def -(another: Pos): Pos

    Subtracts the x and y of the given Pos from the x and y of this Pos, respectively.

    Subtracts the x and y of the given Pos from the x and y of this Pos, respectively. Returns the resulting Pos. The expressions pos1 - pos2 and pos1.subtract(pos2) are equivalent.

    Annotations
    @inline()
  6. def /(divisor: Double): Pos

    Returns a Pos whose two coordinates are obtained by dividing this one’s x and y by the given number.

    Returns a Pos whose two coordinates are obtained by dividing this one’s x and y by the given number. For instance, (20,-30) divided by 10 is (2,-3). The expressions myPos / n and myPos.divide(n) are equivalent.

    Annotations
    @inline()
  7. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def add(pos: Pos): Pos

    Adds the x and y of the given Pos to the x and y of this Pos, respectively.

    Adds the x and y of the given Pos to the x and y of this Pos, respectively. Returns the resulting Pos. The expressions pos1.add(pos2), pos1.offset(pos2), and pos1 + pos2 are equivalent.

    Annotations
    @inline()
  9. def add(dx: Double, dy: Double): Pos

    Adds the two given values to the x and y of this Pos, respectively.

    Adds the two given values to the x and y of this Pos, respectively. Returns the resulting Pos. The expressions myPosadd(dx, dy) and myPosoffset(dx, dy) are equivalent.

    Annotations
    @inline()
  10. def addX(dx: Double): Pos

    Returns a Pos whose x coordinate is greater than this Pos’s by the given amount.

    Returns a Pos whose x coordinate is greater than this Pos’s by the given amount.

    Annotations
    @inline()
  11. def addY(dy: Double): Pos

    Returns a Pos whose y coordinate is greater than this Pos’s by the given amount.

    Returns a Pos whose y coordinate is greater than this Pos’s by the given amount.

    Annotations
    @inline()
  12. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  13. def clamp(xMin: Double, xMax: Double, yMin: Double, yMax: Double): Pos

    Returns a Pos that is as close to this Pos as possible but whose x and y are between the given lower and upper bounds (inclusive).

    Returns a Pos that is as close to this Pos as possible but whose x and y are between the given lower and upper bounds (inclusive).

    xMin

    the least possible value of x in the resulting Pos; must not exceed xMax

    xMax

    the greatest possible value of x in the resulting Pos; must not be below xMin

    yMin

    the least possible value of y in the resulting Pos; must not exceed yMax

    yMax

    the greatest possible value of y in the resulting Pos; must not be below yMin

    Annotations
    @inline()
    See also

    noLowerThan, noHigherThan, noFurtherLeftThan, noFurtherRightThan, clampX, clampY

  14. def clampX(min: Double, max: Double): Pos

    Returns a Pos that is as close to this Pos as possible but whose x is between the given lower and upper bounds (inclusive).

    Returns a Pos that is as close to this Pos as possible but whose x is between the given lower and upper bounds (inclusive).

    min

    the least possible value of x in the resulting Pos; must not exceed max

    max

    the greatest possible value of x in the resulting Pos; must not be below min

    Annotations
    @inline()
    See also

    noFurtherLeftThan, noFurtherRightThan, clampY, clamp

  15. def clampY(min: Double, max: Double): Pos

    Returns a Pos that is as close to this Pos as possible but whose y is between the given lower and upper bounds (inclusive).

    Returns a Pos that is as close to this Pos as possible but whose y is between the given lower and upper bounds (inclusive).

    min

    the least possible value of y in the resulting Pos; must not exceed max

    max

    the greatest possible value of y in the resulting Pos; must not be below min

    Annotations
    @inline()
    See also

    noLowerThan, noHigherThan, clampX, clamp

  16. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  17. def directionOf(destination: Pos): Direction

    Returns the Direction from this Pos towards the given other Pos.

    Returns the Direction from this Pos towards the given other Pos.

    Annotations
    @inline()
  18. def distance(another: Pos): Double

    Returns the distance between this Pos and the given Pos “as the crow flies”.

    Returns the distance between this Pos and the given Pos “as the crow flies”.

    Annotations
    @inline()
  19. def divide(divisor: Double): Pos

    Returns a Pos whose two coordinates are obtained by dividing this one’s x and y by the given number.

    Returns a Pos whose two coordinates are obtained by dividing this one’s x and y by the given number. For instance, (20,-30) divided by 10 is (2,-3). The expressions myPos.divide(n) and myPos / n are equivalent.

    Annotations
    @inline()
  20. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  22. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  23. def multiply(factor: Double): Pos

    Returns a Pos whose two coordinates are obtained by multiplying this one’s x and y by the given factor.

    Returns a Pos whose two coordinates are obtained by multiplying this one’s x and y by the given factor. For instance, (2,-3) multiplied by 10 is (20,-30). The expressions myPos.multiply(n) and myPos * n are equivalent.

    Annotations
    @inline()
  24. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. def nextPos(velocity: Velocity): Pos

    Returns the Pos that an object moving at the given velocity reaches in one unit of time.

    Returns the Pos that an object moving at the given velocity reaches in one unit of time. That is, adds the dx and dy components of the given velocity to this Pos and returns the result.

    Annotations
    @inline()
  26. def noFurtherLeftThan(xMin: Double): Pos

    Returns a Pos that is as close to this Pos as possible but has a x coordinate equal to or greater than the given limit.

    Returns a Pos that is as close to this Pos as possible but has a x coordinate equal to or greater than the given limit.

    Annotations
    @inline()
    See also

    noHigherThan, noFurtherRightThan, clampX, clamp

  27. def noFurtherRightThan(xMax: Double): Pos

    Returns a Pos that is as close to this Pos as possible but has a y coordinate less than or equal to the given limit.

    Returns a Pos that is as close to this Pos as possible but has a y coordinate less than or equal to the given limit.

    Annotations
    @inline()
    See also

    noLowerThan, noFurtherLeftThan, clampX, clamp

  28. def noHigherThan(yMin: Double): Pos

    Returns a Pos that is as close to this Pos as possible but has a y coordinate equal to or greater than the given limit.

    Returns a Pos that is as close to this Pos as possible but has a y coordinate equal to or greater than the given limit.

    Annotations
    @inline()
    See also

    noLowerThan, noFurtherLeftThan, clampY, clamp

  29. def noLowerThan(yMax: Double): Pos

    Returns a Pos that is as close to this Pos as possible but has a y coordinate less than or equal to the given limit.

    Returns a Pos that is as close to this Pos as possible but has a y coordinate less than or equal to the given limit.

    Annotations
    @inline()
    See also

    noHigherThan, noFurtherRightThan, clampY, clamp

  30. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  31. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  32. def offset(another: Pos): Pos

    Returns the Pos that is removed from this Pos by the amount indicated by the given Pos.

    Returns the Pos that is removed from this Pos by the amount indicated by the given Pos. The expressions pos1.offset(pos2), pos1.add(pos2), and pos1 + pos2 are equivalent.

    Annotations
    @inline()
  33. def offset(dx: Double, dy: Double): Pos

    Returns the Pos that is dx and dy removed from this Pos.

    Returns the Pos that is dx and dy removed from this Pos. The expressions myPosoffset(dx, dy) and myPosadd(dx, dy) are equivalent.

    Annotations
    @inline()
  34. def productElementNames: Iterator[String]
    Definition Classes
    Product
  35. def roughly: String

    Returns a String description of the Pos that is identical to toString except it has two decimals for each coordinate.

    Returns a String description of the Pos that is identical to toString except it has two decimals for each coordinate.

    Annotations
    @inline()
  36. def setX(newX: Double): Pos

    Returns a Pos whose x equals the given value and whose y equals this Pos’s y.

    Returns a Pos whose x equals the given value and whose y equals this Pos’s y.

    Annotations
    @inline()
  37. def setY(newY: Double): Pos

    Returns a Pos whose x equals this Pos’s x and whose y equals the given value.

    Returns a Pos whose x equals this Pos’s x and whose y equals the given value.

    Annotations
    @inline()
  38. def subtract(another: Pos): Pos

    Subtracts the x and y of the given Pos from the x and y of this Pos, respectively.

    Subtracts the x and y of the given Pos from the x and y of this Pos, respectively. Returns the resulting Pos. The expressions pos1.subtract(pos2) and pos1 - pos2 are equivalent.

    Annotations
    @inline()
  39. def subtractX(dx: Double): Pos

    Returns a Pos whose x coordinate is less than this Pos’s by the given amount.

    Returns a Pos whose x coordinate is less than this Pos’s by the given amount.

    Annotations
    @inline()
  40. def subtractY(dy: Double): Pos

    Returns a Pos whose y coordinate is less than this Pos’s by the given amount.

    Returns a Pos whose y coordinate is less than this Pos’s by the given amount.

    Annotations
    @inline()
  41. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  42. def toPair: (Double, Double)

    Returns the x and y coordinates of the Pos as a tuple.

    Returns the x and y coordinates of the Pos as a tuple.

    Annotations
    @inline()
  43. def toString: String

    Returns a String description of the Pos.

    Returns a String description of the Pos. It has the form "(x,y)".

    Definition Classes
    Pos → AnyRef → Any
    Annotations
    @inline()
    See also

    roughly

  44. def turnInto[Result](f: (Double, Double) => Result): Result

    Applies the given function to the two coordinates of the Pos and returns the result.

    Applies the given function to the two coordinates of the Pos and returns the result.

    Annotations
    @inline()
  45. def unary_-: Pos

    Returns the Pos that is the opposite of this Pos.

    Returns the Pos that is the opposite of this Pos. For instance, the opposite of (2,-3) is (-2,3).

    Annotations
    @inline()
  46. def vectorTo(destination: Pos): Pos

    Returns a Pos those x and y capture the relative distance from this Pos towards the given Pos.

    Returns a Pos those x and y capture the relative distance from this Pos towards the given Pos. That is, subtracts the x and y of the this Pos from the x and y of given Pos, respectively. The expressions pos1.vectorTo(pos2) and pos2 - pos1 are equivalent.

    Annotations
    @inline()
  47. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  48. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  49. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  50. def withX(computeNew: (Double) => Double): Pos

    Returns a Pos whose x is determined by applying the given function to the x of this Pos and whose y equals that of this Pos.

    Returns a Pos whose x is determined by applying the given function to the x of this Pos and whose y equals that of this Pos.

    computeNew

    a function that takes in an x coordinate and returns the x for the resulting Pos

    Annotations
    @inline()
  51. def withXY(computeNew: (Double, Double) => (Double, Double)): Pos

    Returns a Pos whose x and y are determined by applying the given function to the x and y of this Pos.

    Returns a Pos whose x and y are determined by applying the given function to the x and y of this Pos.

    computeNew

    a function that takes in an x and a y and returns a pair that contains the coordinates of the resulting Pos

    Annotations
    @inline()
  52. def withY(computeNew: (Double) => Double): Pos

    Returns a Pos whose x equals that of this Pos and whose y is determined by applying the given function to the y of this Pos.

    Returns a Pos whose x equals that of this Pos and whose y is determined by applying the given function to the y of this Pos.

    computeNew

    a function that takes in a y coordinate and returns the y for the resulting Pos

    Annotations
    @inline()
  53. val x: Double
  54. def xDiff(another: Pos): Double

    Returns the difference between this Pos’s x coordinate and the given one’s.

    Returns the difference between this Pos’s x coordinate and the given one’s.

    returns

    the difference, which is positive if the given Pos’s x is greater than this one’s and negative if the reverse is true

    Annotations
    @inline()
  55. val y: Double
  56. def yDiff(another: Pos): Double

    Returns the difference between this Pos’s y coordinate and the given one’s.

    Returns the difference between this Pos’s y coordinate and the given one’s.

    returns

    the difference, which is positive if the given Pos’s y is greater than this one’s and negative if the reverse is true

    Annotations
    @inline()

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped