O1Library Docs
Fall 2023
Docs API

# o1.world

package o1.world

## Members list

### Packages

package o1.world.objects

### Type members

#### Classlikes

final case class Bounds(left: Double, top: Double, width: Double, height: Double)

A `Bounds` represents the dimensions of a rectangular area in two-dimensional space.

A `Bounds` represents the dimensions of a rectangular area in two-dimensional space.

`Bounds` objects are immutable. They assume a space in which x coordinates increase rightwards and y coordinates downwards.

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

## Parameters

height

  the height of the `Bounds` (the distance from its top edge to its bottom edge)

left

  the x coordinate of the left edge of the `Bounds`

top

  the y coordinate of the top edge of the `Bounds`

width

  the width of the `Bounds` (the distance from its left edge to its right edge)

## Attributes

Companion
  object
Supertypes
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all

object Bounds

A companion object for class `Bounds`. Provides a factory method.

A companion object for class `Bounds`. Provides a factory method.

## Attributes

Companion
  class
Supertypes
  trait Product
  trait Mirror
  class Object
  trait Matchable
  class Any
Self type
  Bounds.type

sealed case class Direction

Each instance of this class represents a direction on a two-dimensional plane. A direction consists of two components: `dx` and `dy`, each of which is a number between -1.0 and +1.0 (inclusive). `dx` indicates the degree to which the x coordinate changes when moving in that direction; `dy` is the same for the y coordinate. The x coordinate increases rightwards and y downwards.

Each instance of this class represents a direction on a two-dimensional plane. A direction consists of two components: `dx` and `dy`, each of which is a number between -1.0 and +1.0 (inclusive). `dx` indicates the degree to which the x coordinate changes when moving in that direction; `dy` is the same for the y coordinate. The x coordinate increases rightwards and y downwards.

For example, moving straight rightwards can be thought of a moving in a `Direction` with a `dx` of +1.0 and a `dy` of 0.0; by comparison, the upward direction would have a `dx` of 0.0 and a `dy` of -1.0. . Diagonals have non-zero values for both `dx` and `dy`.

The `dx` and `dy` of any `Direction` always sum up to (roughly) 1.0, with the exception of the special value NoDirection which represents the lack of a direction and as zero for both components. (In this, a `Direction` is different than a Velocity, which is a combination of a direction of movement and a speed.)

You don’t instantiate `Direction` directly; instead, you create `Direction`s with the methods on this class’s companion object. Among other things, you can:

- construct a direction from two differences between coordinates, as in `Direction.fromDeltas(-100, 50)`; or
- create a direction that corresponds to a given angle, as in `Direction.fromDegrees(60)` and `Direction.fromRadians(-scala.math.Pi / 4)`.

Some of the methods of a `Direction` object also create and return new `Direction`s, as does the directionOf method on `Pos` objects. Moreover, this class’s companion object has a few predefined `Direction` constants: Up Down, Left, Right, and NoDirection.

`Direction` 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

dx

  the amount of change in the x coordinate when moving in this direction, relative to `dy`

dy

  the amount of change in the y coordinate when moving in this direction, relative to `dx`

## Attributes

Companion
  object
Supertypes
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all

object Direction

This companion object of class `Direction` provides some constants of type `Direction` and methods for creating new `Direction` instances.

This companion object of class `Direction` provides some constants of type `Direction` and methods for creating new `Direction` instances.

The object has an alias in the top-level package o1, so it’s accessible to students simply via `import o1.*`.

## Attributes

Companion
  class
Supertypes
  trait Product
  trait Mirror
  class Object
  trait Matchable
  class Any
Self type
  Direction.type

final case class Pos(x: Double, y: Double)

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.

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
Supertypes
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all

object Pos

This companion object of class `Pos` provides alternative methods for creating new `Pos` objects. It has an alias in the top-level package o1, so it’s accessible to students simply via `import o1._`.

This companion object of class `Pos` provides alternative methods for creating new `Pos` objects. It has an alias in the top-level package o1, so it’s accessible to students simply via `import o1._`.

## Attributes

Companion
  class
Supertypes
  trait Product
  trait Mirror
  class Object
  trait Matchable
  class Any
Self type
  Pos.type

final case class Velocity(direction: Direction, speed: Double)

Each instance of this class represents movement in the context of a two-dimensional plane. A velocity is a combination of a Direction of movement with a speed (a non-negative `Double`).

Each instance of this class represents movement in the context of a two-dimensional plane. A velocity is a combination of a Direction of movement with a speed (a non-negative `Double`).

Another way to think about a `Velocity` is to divide it in two components: `dx` and `dy`. `dx` indicates the amount (and direction) of movement along the x axis; `dy` is the same for the y axis. The x coordinate increases rightwards and y downwards. For instance, a velocity with a `dx` of 10 and a `dy` of zero indicates rightward movement, and a velocity with a `dx` of -100 and a `dy` of -100 indicates faster movement leftwards and upwards.

There are many ways to create a `Velocity` using the methods on the companion object. Among other things, you can:

- construct a velocity from a direction and a (positive or zero) speed, as in `Velocity(Direction.Left, 50)`;
- construct a direction from `dx` and `dy`, as in `Velocity(-100, 50)`; or
- determine the velocity needed to go from one Pos to another in a single unit of time, as in `Velocity.between(pos1, pos2)`.

Many of the methods on `Velocity` objects also create and return new velocities.

`Velocity` 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

direction

  the direction of movement

speed

  the speed of movement; this cannot be negative

## Attributes

Companion
  object
Supertypes
  trait Serializable
  trait Product
  trait Equals
  class Object
  trait Matchable
  class Any
  Show all

object Velocity

This companion object of class `Velocity` exists primarily to provide convenience methods for creating new instances of `Velocity`.

This companion object of class `Velocity` exists primarily to provide convenience methods for creating new instances of `Velocity`.

The object has an alias in the top-level package o1, so it’s accessible to students simply via `import o1.*`.

## Attributes

Companion
  class
Supertypes
  trait Product
  trait Mirror
  class Object
  trait Matchable
  class Any
Self type
  Velocity.type