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.*
.
Parameters
- x
-
the x coordinate of the
Pos
- y
-
the y coordinate of the
Pos
Attributes
- Companion
- object
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
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.
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.
Attributes
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.
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.
Attributes
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.
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.
Attributes
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.
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.
Attributes
Adds the two given values to the x
and y
of this Pos
, respectively. Returns the resulting Pos
. The expressions myPos.add(dx, dy)
and myPos.offset(dx, dy)
are equivalent.
Adds the two given values to the x
and y
of this Pos
, respectively. Returns the resulting Pos
. The expressions myPos.add(dx, dy)
and myPos.offset(dx, dy)
are equivalent.
Attributes
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.
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.
Attributes
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.
Attributes
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.
Attributes
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).
Parameters
- xMax
-
the greatest possible value of
x
in the resultingPos
; must not be belowxMin
- xMin
-
the least possible value of
x
in the resultingPos
; must not exceedxMax
- yMax
-
the greatest possible value of
y
in the resultingPos
; must not be belowyMin
- yMin
-
the least possible value of
y
in the resultingPos
; must not exceedyMax
Attributes
- See also
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).
Parameters
- max
-
the greatest possible value of
x
in the resultingPos
; must not be belowmin
- min
-
the least possible value of
x
in the resultingPos
; must not exceedmax
Attributes
- See also
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).
Parameters
- max
-
the greatest possible value of
y
in the resultingPos
; must not be belowmin
- min
-
the least possible value of
y
in the resultingPos
; must not exceedmax
Attributes
- See also
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”.
Attributes
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.
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.
Attributes
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.
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.
Attributes
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.
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.
Attributes
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.
Attributes
- See also
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.
Attributes
- See also
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.
Attributes
- See also
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.
Attributes
- See also
Returns the Pos
that is dx
and dy
removed from this Pos
. The expressions myPos.offset(dx, dy)
and myPos.add(dx, dy)
are equivalent.
Returns the Pos
that is dx
and dy
removed from this Pos
. The expressions myPos.offset(dx, dy)
and myPos.add(dx, dy)
are equivalent.
Attributes
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.
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.
Attributes
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
.
Attributes
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.
Attributes
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.
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.
Attributes
Subtracts the two given values from the the x
and y
of this Pos
, respectively. Returns the resulting Pos
.
Subtracts the two given values from the the x
and y
of this Pos
, respectively. Returns the resulting Pos
.
Attributes
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.
Attributes
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.
Attributes
Returns the x
and y
coordinates of the Pos
as a tuple.
Returns the x
and y
coordinates of the Pos
as a tuple.
Attributes
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.
Attributes
Returns the Pos
that is the opposite of this Pos
. For instance, the opposite of (2,-3) is (-2,3).
Returns the Pos
that is the opposite of this Pos
. For instance, the opposite of (2,-3) is (-2,3).
Attributes
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.
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.
Attributes
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
.
Parameters
- computeNew
-
a function that takes in an x coordinate and returns the x for the resulting
Pos
Attributes
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
.
Parameters
- computeNew
-
a function that takes in an x and a y and returns a pair that contains the coordinates of the resulting
Pos
Attributes
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
.
Parameters
- computeNew
-
a function that takes in a y coordinate and returns the y for the resulting
Pos
Attributes
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.
Attributes
- Returns
-
the difference, which is positive if the given
Pos
’sx
is greater than this one’s and negative if the reverse is true
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.
Attributes
- Returns
-
the difference, which is positive if the given
Pos
’sy
is greater than this one’s and negative if the reverse is true