O1Library Docs
Fall 2023
Docs API

# MovingObjectInContainer

o1.world.objects.mutable$.MovingObjectInContainer
trait MovingObjectInContainer extends ContainedObject, HasVelocity

A supertype for objects that take up a rectangular area and have a velocity as well as a mutable position that may be constrained by a larger object around them.

## Attributes

Graph
Supertypes
  trait HasVelocity
  trait ContainedObject
  trait HasContainer
  trait HasEdges
  trait HasAnchor
  trait HasSize
  trait MutablePos
  trait HasPos
  class Object
  trait Matchable
  class Any
  Show all

## Members list

### Value members

#### Concrete methods

def moveFreely(): Unit

Causes the object’s pos to change: the object moves from its current location at its current velocity for one unit of time. That is, the `dx` and `dy` components of the velocity are added to the object’s pos.

Causes the object’s pos to change: the object moves from its current location at its current velocity for one unit of time. That is, the `dx` and `dy` components of the velocity are added to the object’s pos.

## Attributes

def moveWithinContainer(): Unit

Causes the object’s pos to change: the object moves from its current location at its current velocity for one unit of time (as per moveFreely) and is then immediately clamped to the object’s container (as per `bringToContainer`).

Causes the object’s pos to change: the object moves from its current location at its current velocity for one unit of time (as per moveFreely) and is then immediately clamped to the object’s container (as per `bringToContainer`).

## Attributes

#### Inherited methods

def anchor: Anchor

Returns the object’s anchoring point, which is Anchor.Center unless overridden.

Returns the object’s anchoring point, which is Anchor.Center unless overridden.

## Attributes

Inherited from:
  HasEdges

def bottom: Double

Returns the y coordinate of the bottom edge.

Returns the y coordinate of the bottom edge.

## Attributes

Inherited from:
  HasEdges

def bottomLeft: Pos

Returns the coordinates of this object’s bottom left-hand corner.

Returns the coordinates of this object’s bottom left-hand corner.

## Attributes

Inherited from:
  HasEdges

def bottomRight: Pos

Returns the coordinates of this object’s bottom right-hand corner.

Returns the coordinates of this object’s bottom right-hand corner.

## Attributes

Inherited from:
  HasEdges

def bringToContainer(): Unit

Causes this object’s pos to change so that the object is within its container, as per `clamp`.

Causes this object’s pos to change so that the object is within its container, as per `clamp`.

## Attributes

Inherited from:
  ContainedObject

def bringXToContainer(): Unit

Causes this object’s pos to change so that its left and right edges don’t extend beyond its container, as per `clampX`.

Causes this object’s pos to change so that its left and right edges don’t extend beyond its container, as per `clampX`.

## Attributes

Inherited from:
  ContainedObject

def bringYToContainer(): Unit

Causes this object’s pos to change so that its top and bottom edges don’t extend beyond its container, as per `clampY`.

Causes this object’s pos to change so that its top and bottom edges don’t extend beyond its container, as per `clampY`.

## Attributes

Inherited from:
  ContainedObject

def center: Pos

Returns the average position between this object’s edges.

Returns the average position between this object’s edges.

## Attributes

Inherited from:
  HasEdges

def centerFromTopLeft: Pos

the location of this object’s center: the average point between its edges, expressed in coordinates relative to the object’s top left-hand corner

the location of this object’s center: the average point between its edges, expressed in coordinates relative to the object’s top left-hand corner

## Attributes

Inherited from:
  HasSize

def clamp(): Pos

Looks for a position for this object that is as close to possible to the object’s current pos but keeps the object’s edges within the bounds of the object’s container. Returns that `Pos`.

Looks for a position for this object that is as close to possible to the object’s current pos but keeps the object’s edges within the bounds of the object’s container. Returns that `Pos`.

## Attributes

Inherited from:
  HasContainer

def clampWhollyInside(container: HasEdges, desiredPosition: Pos): Pos

Looks for a position for this object that is as close to possible to a particular target position but keeps the object’s edges within the bounds of the given other object.

Looks for a position for this object that is as close to possible to a particular target position but keeps the object’s edges within the bounds of the given other object.

## Parameters

container

  another object that sets the boundaries for the return value

desiredPosition

  the ideal position for this object (defaults to the object’s current pos)

## Attributes

Returns

  the location closest to `desiredPosition` where this object’s anchor can be placed without its edges extending beyond `container`

Inherited from:
  HasEdges

def clampX(): Pos

Looks for a position for this object that is as close to possible to the object’s current pos but keeps the left and right edges of the object within the bounds of the object’s container. Returns that `Pos`.

Looks for a position for this object that is as close to possible to the object’s current pos but keeps the left and right edges of the object within the bounds of the object’s container. Returns that `Pos`.

## Attributes

Inherited from:
  HasContainer

def clampXWhollyInside(container: HasEdges, desiredPosition: Pos): Pos

Looks for a position for this object that is as close to possible to a particular target position but keeps the left and right edges of the object within the bounds of the given other object.

Looks for a position for this object that is as close to possible to a particular target position but keeps the left and right edges of the object within the bounds of the given other object.

## Parameters

container

  another object that sets the boundaries for the return value

desiredPosition

  the ideal position for this object (defaults to the object’s current pos)

## Attributes

Returns

  the location closest to `desiredPosition` where this object’s anchor can be placed without its left or right edge extending beyond `container`

Inherited from:
  HasEdges

def clampY(): Pos

Looks for a position for this object that is as close to possible to the object’s current pos but keeps the top and bottom edges of the object within the bounds of the object’s container. Returns that `Pos`.

Looks for a position for this object that is as close to possible to the object’s current pos but keeps the top and bottom edges of the object within the bounds of the object’s container. Returns that `Pos`.

## Attributes

Inherited from:
  HasContainer

def clampYWhollyInside(container: HasEdges, desiredPosition: Pos): Pos

Looks for a position for this object that is as close to possible to a particular target position but keeps the top and bottom edges of the object within the bounds of the given other object.

Looks for a position for this object that is as close to possible to a particular target position but keeps the top and bottom edges of the object within the bounds of the given other object.

## Parameters

container

  another object that sets the boundaries for the return value

desiredPosition

  the ideal position for this object (defaults to the object’s current pos)

## Attributes

Returns

  the location closest to `desiredPosition` where this object’s anchor can be placed without its top or bottom edge extending beyond `container`

Inherited from:
  HasEdges

def closestPosTo(target: Pos): Pos

Returns the position within this object’s edges that is as close as possible to the given position.

Returns the position within this object’s edges that is as close as possible to the given position.

## Attributes

Inherited from:
  HasEdges

def containsBetweenEdges(candidate: Pos): Boolean

Determines whether the given `Pos`’s x coordinate is between this object’s left edge (inclusive) and its right edge (exclusive) and if it’s y coordinate is similarly between the top and bottom edges.

Determines whether the given `Pos`’s x coordinate is between this object’s left edge (inclusive) and its right edge (exclusive) and if it’s y coordinate is similarly between the top and bottom edges.

## Attributes

Inherited from:
  HasEdges

def distance(another: HasPos): Double

Determines the distance (“as the crow flies”) between this object’s `pos` and that of the given object.

Determines the distance (“as the crow flies”) between this object’s `pos` and that of the given object.

## Attributes

Inherited from:
  HasPos

def height: Double

this object’s height: the distance from its top edge to its bottom edge

this object’s height: the distance from its top edge to its bottom edge

## Attributes

Inherited from:
  HasSize

def internalAnchorPos: Pos

Returns the Pos of the anchoring point within this object, expressed as coordinates relative to the object’s top left-hand corner.

Returns the Pos of the anchoring point within this object, expressed as coordinates relative to the object’s top left-hand corner.

## Attributes

Inherited from:
  HasAnchor

def internalAnchorX: Double

Returns the x coordinate of the anchoring point within this object, relative to the object’s left edge.

Returns the x coordinate of the anchoring point within this object, relative to the object’s left edge.

## Attributes

Inherited from:
  HasAnchor

def internalAnchorY: Double

Returns the y coordinate of the anchoring point within this object, relative to the object’s top edge.

Returns the y coordinate of the anchoring point within this object, relative to the object’s top edge.

## Attributes

Inherited from:
  HasAnchor

def isBoundFor(direction: Direction): Boolean

Determines whether this object is bound for roughly the given direction, as per Direction.sharesQuadrant.

Determines whether this object is bound for roughly the given direction, as per Direction.sharesQuadrant.

## Attributes

Inherited from:
  HasVelocity

def isDownbound: Boolean

Determines whether this object has a downward velocity, as per Direction.isDownward.

Determines whether this object has a downward velocity, as per Direction.isDownward.

## Attributes

Inherited from:
  HasVelocity

def isLeftbound: Boolean

Determines whether this object has a leftward velocity, as per Direction.isLeftward.

Determines whether this object has a leftward velocity, as per Direction.isLeftward.

## Attributes

Inherited from:
  HasVelocity

def isRightbound: Boolean

Determines whether this object has a rightward velocity, as per Direction.isRightward.

Determines whether this object has a rightward velocity, as per Direction.isRightward.

## Attributes

Inherited from:
  HasVelocity

def isUpbound: Boolean

Determines whether this object has an upward velocity, as per Direction.isUpward.

Determines whether this object has an upward velocity, as per Direction.isUpward.

## Attributes

Inherited from:
  HasVelocity

def left: Double

Returns the x coordinate of this object’s left edge.

Returns the x coordinate of this object’s left edge.

## Attributes

Inherited from:
  HasEdges

def nextPos: Pos

Returns the `Pos` that this object, moving from its current location at its current velocity, reaches in one unit of time. That is, adds the `dx` and `dy` components of the velocity to the current `Pos` and returns the result.

Returns the `Pos` that this object, moving from its current location at its current velocity, reaches in one unit of time. That is, adds the `dx` and `dy` components of the velocity to the current `Pos` and returns the result.

## Attributes

Inherited from:
  HasVelocity

def right: Double

Returns the x coordinate of the right edge.

Returns the x coordinate of the right edge.

## Attributes

Inherited from:
  HasEdges

def top: Double

Returns the y coordinate of the top edge.

Returns the y coordinate of the top edge.

## Attributes

Inherited from:
  HasEdges

def topLeft: Pos

Returns the coordinates of this object’s top left-hand corner.

Returns the coordinates of this object’s top left-hand corner.

## Attributes

Inherited from:
  HasEdges

def topRight: Pos

Returns the coordinates of this object’s top right-hand corner.

Returns the coordinates of this object’s top right-hand corner.

## Attributes

Inherited from:
  HasEdges

def velocity: Velocity

the object’s velocity

the object’s velocity

## Attributes

Inherited from:
  HasVelocity

def width: Double

this object’s width: the distance from its left edge to its right edge

this object’s width: the distance from its left edge to its right edge

## Attributes

Inherited from:
  HasSize

#### Inherited fields

val container: HasEdges

another object that clampX, clampY, and clamp use for constraining this object’s position

another object that clampX, clampY, and clamp use for constraining this object’s position

## Attributes

Inherited from:
  HasContainer

var pos: Pos

the object’s location

the object’s location

## Attributes

Inherited from:
  MutablePos