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
- Alphabetic
- By Inheritance
- Pos
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new Pos(x: Double, y: Double)
- x
the x coordinate of the
Pos
- y
the y coordinate of the
Pos
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- def *(factor: Double): Pos
Returns a
Pos
whose two coordinates are obtained by multiplying this one’sx
andy
by the given factor.Returns a
Pos
whose two coordinates are obtained by multiplying this one’sx
andy
by the given factor. For instance, (2,-3) multiplied by 10 is (20,-30). The expressionsmyPos * n
andmyPos.multiply(n)
are equivalent.- Annotations
- @inline()
- def +(another: Pos): Pos
Adds the
x
andy
of the givenPos
to thex
andy
of thisPos
, respectively.Adds the
x
andy
of the givenPos
to thex
andy
of thisPos
, respectively. Returns the resultingPos
. The expressionspos1 + pos2
,pos1.add(pos2)
, andpos1.offset(pos2)
are equivalent.- Annotations
- @inline()
- def -(another: Pos): Pos
Subtracts the
x
andy
of the givenPos
from thex
andy
of thisPos
, respectively.Subtracts the
x
andy
of the givenPos
from thex
andy
of thisPos
, respectively. Returns the resultingPos
. The expressionspos1 - pos2
andpos1.subtract(pos2)
are equivalent.- Annotations
- @inline()
- def /(divisor: Double): Pos
Returns a
Pos
whose two coordinates are obtained by dividing this one’sx
andy
by the given number.Returns a
Pos
whose two coordinates are obtained by dividing this one’sx
andy
by the given number. For instance, (20,-30) divided by 10 is (2,-3). The expressionsmyPos / n
andmyPos.divide(n)
are equivalent.- Annotations
- @inline()
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def add(pos: Pos): Pos
Adds the
x
andy
of the givenPos
to thex
andy
of thisPos
, respectively.Adds the
x
andy
of the givenPos
to thex
andy
of thisPos
, respectively. Returns the resultingPos
. The expressionspos1.add(pos2)
,pos1.offset(pos2)
, andpos1 + pos2
are equivalent.- Annotations
- @inline()
- def add(dx: Double, dy: Double): Pos
Adds the two given values to the
x
andy
of thisPos
, respectively.Adds the two given values to the
x
andy
of thisPos
, respectively. Returns the resultingPos
. The expressionsmyPosadd(dx, dy)
andmyPosoffset(dx, dy)
are equivalent.- Annotations
- @inline()
- def addX(dx: Double): Pos
Returns a
Pos
whosex
coordinate is greater than thisPos
’s by the given amount.Returns a
Pos
whosex
coordinate is greater than thisPos
’s by the given amount.- Annotations
- @inline()
- def addY(dy: Double): Pos
Returns a
Pos
whosey
coordinate is greater than thisPos
’s by the given amount.Returns a
Pos
whosey
coordinate is greater than thisPos
’s by the given amount.- Annotations
- @inline()
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clamp(xMin: Double, xMax: Double, yMin: Double, yMax: Double): Pos
Returns a
Pos
that is as close to thisPos
as possible but whosex
andy
are between the given lower and upper bounds (inclusive).Returns a
Pos
that is as close to thisPos
as possible but whosex
andy
are between the given lower and upper bounds (inclusive).- xMin
the least possible value of
x
in the resultingPos
; must not exceedxMax
- xMax
the greatest possible value of
x
in the resultingPos
; must not be belowxMin
- yMin
the least possible value of
y
in the resultingPos
; must not exceedyMax
- yMax
the greatest possible value of
y
in the resultingPos
; must not be belowyMin
- Annotations
- @inline()
- See also
noLowerThan, noHigherThan, noFurtherLeftThan, noFurtherRightThan, clampX, clampY
- def clampX(min: Double, max: Double): Pos
Returns a
Pos
that is as close to thisPos
as possible but whosex
is between the given lower and upper bounds (inclusive).Returns a
Pos
that is as close to thisPos
as possible but whosex
is between the given lower and upper bounds (inclusive).- min
the least possible value of
x
in the resultingPos
; must not exceedmax
- max
the greatest possible value of
x
in the resultingPos
; must not be belowmin
- Annotations
- @inline()
- See also
- def clampY(min: Double, max: Double): Pos
Returns a
Pos
that is as close to thisPos
as possible but whosey
is between the given lower and upper bounds (inclusive).Returns a
Pos
that is as close to thisPos
as possible but whosey
is between the given lower and upper bounds (inclusive).- min
the least possible value of
y
in the resultingPos
; must not exceedmax
- max
the greatest possible value of
y
in the resultingPos
; must not be belowmin
- Annotations
- @inline()
- See also
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def directionOf(destination: Pos): Direction
Returns the Direction from this
Pos
towards the given otherPos
.Returns the Direction from this
Pos
towards the given otherPos
.- Annotations
- @inline()
- def distance(another: Pos): Double
Returns the distance between this
Pos
and the givenPos
“as the crow flies”.Returns the distance between this
Pos
and the givenPos
“as the crow flies”.- Annotations
- @inline()
- def divide(divisor: Double): Pos
Returns a
Pos
whose two coordinates are obtained by dividing this one’sx
andy
by the given number.Returns a
Pos
whose two coordinates are obtained by dividing this one’sx
andy
by the given number. For instance, (20,-30) divided by 10 is (2,-3). The expressionsmyPos.divide(n)
andmyPos / n
are equivalent.- Annotations
- @inline()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def multiply(factor: Double): Pos
Returns a
Pos
whose two coordinates are obtained by multiplying this one’sx
andy
by the given factor.Returns a
Pos
whose two coordinates are obtained by multiplying this one’sx
andy
by the given factor. For instance, (2,-3) multiplied by 10 is (20,-30). The expressionsmyPos.multiply(n)
andmyPos * n
are equivalent.- Annotations
- @inline()
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- 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 thedx
anddy
components of the given velocity to thisPos
and returns the result.- Annotations
- @inline()
- def noFurtherLeftThan(xMin: Double): Pos
Returns a
Pos
that is as close to thisPos
as possible but has ax
coordinate equal to or greater than the given limit.Returns a
Pos
that is as close to thisPos
as possible but has ax
coordinate equal to or greater than the given limit.- Annotations
- @inline()
- See also
- def noFurtherRightThan(xMax: Double): Pos
Returns a
Pos
that is as close to thisPos
as possible but has ay
coordinate less than or equal to the given limit.Returns a
Pos
that is as close to thisPos
as possible but has ay
coordinate less than or equal to the given limit.- Annotations
- @inline()
- See also
- def noHigherThan(yMin: Double): Pos
Returns a
Pos
that is as close to thisPos
as possible but has ay
coordinate equal to or greater than the given limit.Returns a
Pos
that is as close to thisPos
as possible but has ay
coordinate equal to or greater than the given limit.- Annotations
- @inline()
- See also
- def noLowerThan(yMax: Double): Pos
Returns a
Pos
that is as close to thisPos
as possible but has ay
coordinate less than or equal to the given limit.Returns a
Pos
that is as close to thisPos
as possible but has ay
coordinate less than or equal to the given limit.- Annotations
- @inline()
- See also
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def offset(another: Pos): Pos
Returns the
Pos
that is removed from thisPos
by the amount indicated by the givenPos
.Returns the
Pos
that is removed from thisPos
by the amount indicated by the givenPos
. The expressionspos1.offset(pos2)
,pos1.add(pos2)
, andpos1 + pos2
are equivalent.- Annotations
- @inline()
- def offset(dx: Double, dy: Double): Pos
Returns the
Pos
that isdx
anddy
removed from thisPos
.Returns the
Pos
that isdx
anddy
removed from thisPos
. The expressionsmyPosoffset(dx, dy)
andmyPosadd(dx, dy)
are equivalent.- Annotations
- @inline()
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- def roughly: String
Returns a
String
description of thePos
that is identical to toString except it has two decimals for each coordinate.Returns a
String
description of thePos
that is identical to toString except it has two decimals for each coordinate.- Annotations
- @inline()
- def setX(newX: Double): Pos
Returns a
Pos
whosex
equals the given value and whosey
equals thisPos
’sy
.Returns a
Pos
whosex
equals the given value and whosey
equals thisPos
’sy
.- Annotations
- @inline()
- def setY(newY: Double): Pos
Returns a
Pos
whosex
equals thisPos
’sx
and whosey
equals the given value.Returns a
Pos
whosex
equals thisPos
’sx
and whosey
equals the given value.- Annotations
- @inline()
- def subtract(another: Pos): Pos
Subtracts the
x
andy
of the givenPos
from thex
andy
of thisPos
, respectively.Subtracts the
x
andy
of the givenPos
from thex
andy
of thisPos
, respectively. Returns the resultingPos
. The expressionspos1.subtract(pos2)
andpos1 - pos2
are equivalent.- Annotations
- @inline()
- def subtractX(dx: Double): Pos
Returns a
Pos
whosex
coordinate is less than thisPos
’s by the given amount.Returns a
Pos
whosex
coordinate is less than thisPos
’s by the given amount.- Annotations
- @inline()
- def subtractY(dy: Double): Pos
Returns a
Pos
whosey
coordinate is less than thisPos
’s by the given amount.Returns a
Pos
whosey
coordinate is less than thisPos
’s by the given amount.- Annotations
- @inline()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toPair: (Double, Double)
Returns the
x
andy
coordinates of thePos
as a tuple.Returns the
x
andy
coordinates of thePos
as a tuple.- Annotations
- @inline()
- def toString: String
Returns a
String
description of thePos
. - 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()
- def unary_-: Pos
Returns the
Pos
that is the opposite of thisPos
.Returns the
Pos
that is the opposite of thisPos
. For instance, the opposite of (2,-3) is (-2,3).- Annotations
- @inline()
- def vectorTo(destination: Pos): Pos
Returns a
Pos
thosex
andy
capture the relative distance from thisPos
towards the givenPos
.Returns a
Pos
thosex
andy
capture the relative distance from thisPos
towards the givenPos
. That is, subtracts thex
andy
of the thisPos
from thex
andy
of givenPos
, respectively. The expressionspos1.vectorTo(pos2)
andpos2 - pos1
are equivalent.- Annotations
- @inline()
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def withX(computeNew: (Double) => Double): Pos
Returns a
Pos
whosex
is determined by applying the given function to thex
of thisPos
and whosey
equals that of thisPos
.Returns a
Pos
whosex
is determined by applying the given function to thex
of thisPos
and whosey
equals that of thisPos
.- computeNew
a function that takes in an x coordinate and returns the x for the resulting
Pos
- Annotations
- @inline()
- def withXY(computeNew: (Double, Double) => (Double, Double)): Pos
Returns a
Pos
whosex
andy
are determined by applying the given function to thex
andy
of thisPos
.Returns a
Pos
whosex
andy
are determined by applying the given function to thex
andy
of thisPos
.- 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()
- def withY(computeNew: (Double) => Double): Pos
Returns a
Pos
whosex
equals that of thisPos
and whosey
is determined by applying the given function to they
of thisPos
.Returns a
Pos
whosex
equals that of thisPos
and whosey
is determined by applying the given function to they
of thisPos
.- computeNew
a function that takes in a y coordinate and returns the y for the resulting
Pos
- Annotations
- @inline()
- val x: Double
- def xDiff(another: Pos): Double
Returns the difference between this
Pos
’sx
coordinate and the given one’s.Returns the difference between this
Pos
’sx
coordinate and the given one’s.- returns
the difference, which is positive if the given
Pos
’sx
is greater than this one’s and negative if the reverse is true
- Annotations
- @inline()
- val y: Double
- def yDiff(another: Pos): Double
Returns the difference between this
Pos
’sy
coordinate and the given one’s.Returns the difference between this
Pos
’sy
coordinate and the given one’s.- returns
the difference, which is positive if the given
Pos
’sy
is greater than this one’s and negative if the reverse is true
- Annotations
- @inline()
Deprecated Value Members
- 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.