Options
Menu

Class Box

A Box object is an area defined by its position, as indicated by its top-left-front corner point(x, y, z) and by its width, height and depth.

The x, y, z, width, height depth properties of the Box export class are independent of each other; changing the value of one property has no effect on the others. However, the right, bottom and back properties are integrally related to those six properties. For example, if you change the value of the right property, the value of the width property changes; if you change the bottom property, the value of the height property changes.

The following methods and properties use Box objects:

  • The bounds property of the DisplayObject class

You can use the new Box() constructor to create a Box object.

Note: The Box export class does not define a cubic Shape display object.

Hierarchy

  • Box

Index

Constructors

constructor

  • new Box(x?: number, y?: number, z?: number, width?: number, height?: number, depth?: number): Box
  • Creates a new Box object with the top-left-front corner specified by the x, y and z parameters and with the specified width, height and depth parameters. If you call this public without parameters, a box with x, y, z, width, height and depth properties set to 0 is created.

    Parameters

    • Default value x: number = 0

      The x coordinate of the top-left-front corner of the box.

    • Default value y: number = 0

      The y coordinate of the top-left-front corner of the box.

    • Default value z: number = 0

      The z coordinate of the top-left-front corner of the box.

    • Default value width: number = 0

      The width of the box, in pixels.

    • Default value height: number = 0

      The height of the box, in pixels.

    • Default value depth: number = 0

      The depth of the box, in pixels.

    Returns Box

Properties

depth

depth: number

The deoth of the box, in pixels. Changing the depth value of a Box object has no effect on the x, y, z, width and height properties.

height

height: number

The height of the box, in pixels. Changing the height value of a Box object has no effect on the x, y, z, depth and width properties.

width

width: number

The width of the box, in pixels. Changing the width value of a Box object has no effect on the x, y, z, depth and height properties.

x

x: number

The x coordinate of the top-left-front corner of the box. Changing the value of the x property of a Box object has no effect on the y, z, width, height and depth properties.

The value of the x property is equal to the value of the left property.

y

y: number

The y coordinate of the top-left-front corner of the box. Changing the value of the y property of a Box object has no effect on the x, z, width, height and depth properties.

The value of the y property is equal to the value of the top property.

z

z: number

The y coordinate of the top-left-front corner of the box. Changing the value of the z property of a Box object has no effect on the x, y, width, height and depth properties.

The value of the z property is equal to the value of the front property.

Accessors

back

  • get (): number
  • set (val: number): void
  • The sum of the z and height properties.

    Returns number

  • The sum of the z and height properties.

    Parameters

    • val: number

    Returns void

bottom

  • get (): number
  • set (val: number): void
  • The sum of the y and height properties.

    Returns number

  • The sum of the y and height properties.

    Parameters

    • val: number

    Returns void

bottomRightBack

  • The location of the Box object's bottom-right corner, determined by the values of the right and bottom properties.

    Returns Vector3D

front

  • get (): number
  • set (val: number): void
  • The z coordinate of the top-left-front corner of the box. Changing the front property of a Box object has no effect on the x, y, width and height properties. However it does affect the depth property, whereas changing the z value does not affect the depth property.

    The value of the left property is equal to the value of the x property.

    Returns number

  • The z coordinate of the top-left-front corner of the box. Changing the front property of a Box object has no effect on the x, y, width and height properties. However it does affect the depth property, whereas changing the z value does not affect the depth property.

    The value of the left property is equal to the value of the x property.

    Parameters

    • val: number

    Returns void

left

  • get (): number
  • set (val: number): void
  • The x coordinate of the top-left corner of the box. Changing the left property of a Box object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.

    The value of the left property is equal to the value of the x property.

    Returns number

  • The x coordinate of the top-left corner of the box. Changing the left property of a Box object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.

    The value of the left property is equal to the value of the x property.

    Parameters

    • val: number

    Returns void

right

  • get (): number
  • set (val: number): void
  • The sum of the x and width properties.

    Returns number

  • The sum of the x and width properties.

    Parameters

    • val: number

    Returns void

size

  • The size of the Box object, expressed as a Vector3D object with the values of the width, height and depth properties.

    Returns Vector3D

top

  • get (): number
  • set (val: number): void
  • The y coordinate of the top-left-front corner of the box. Changing the top property of a Box object has no effect on the x and width properties. However it does affect the height property, whereas changing the y value does not affect the height property.

    The value of the top property is equal to the value of the y property.

    Returns number

  • The y coordinate of the top-left-front corner of the box. Changing the top property of a Box object has no effect on the x and width properties. However it does affect the height property, whereas changing the y value does not affect the height property.

    The value of the top property is equal to the value of the y property.

    Parameters

    • val: number

    Returns void

topLeftFront

  • The location of the Box object's top-left-front corner, determined by the x, y and z coordinates of the point.

    Returns Vector3D

Methods

clone

  • Returns a new Box object with the same values for the x, y, z, width, height and depth properties as the original Box object.

    Returns Box

    A new Box object with the same values for the x, y, z, width, height and depth properties as the original Box object.

closestPointToPoint

  • Finds the closest point on the Box to another given point. This can be used for maximum error calculations for content within a given Box.

    Parameters

    • point: Vector3D

      The point for which to find the closest point on the Box

    • Default value target: Vector3D = null

      An optional Vector3D to store the result to prevent creating a new object.

    Returns Vector3D

contains

  • contains(x: number, y: number, z: number): boolean
  • Determines whether the specified position is contained within the cubic region defined by this Box object.

    Parameters

    • x: number

      The x coordinate(horizontal component) of the position.

    • y: number

      The y coordinate(vertical component) of the position.

    • z: number

      The z coordinate(longitudinal component) of the position.

    Returns boolean

    A value of true if the Box object contains the specified position; otherwise false.

containsBox

  • containsBox(box: Box): boolean
  • Determines whether the Box object specified by the box parameter is contained within this Box object. A Box object is said to contain another if the second Box object falls entirely within the boundaries of the first.

    Parameters

    • box: Box

      The Box object being checked.

    Returns boolean

    A value of true if the Box object that you specify is contained by this Box object; otherwise false.

containsPoint

  • containsPoint(position: Vector3D): boolean
  • Determines whether the specified position is contained within the cubic region defined by this Box object. This method is similar to the Box.contains() method, except that it takes a Vector3D object as a parameter.

    Parameters

    • position: Vector3D

      The position, as represented by its x, y and z coordinates.

    Returns boolean

    A value of true if the Box object contains the specified position; otherwise false.

copyFrom

  • copyFrom(sourceBox: Box): void
  • Copies all of box data from the source Box object into the calling Box object.

    Parameters

    • sourceBox: Box

      The Box object from which to copy the data.

    Returns void

equals

  • equals(toCompare: Box): boolean
  • Determines whether the object specified in the toCompare parameter is equal to this Box object. This method compares the x, y, z, width, height and depth properties of an object against the same properties of this Box object.

    Parameters

    • toCompare: Box

      The box to compare to this Box object.

    Returns boolean

    A value of true if the object has exactly the same values for the x, y, z, width, height and depth properties as this Box object; otherwise false.

inflate

  • inflate(dx: number, dy: number, dz: number): void
  • Increases the size of the Box object by the specified amounts, in pixels. The center point of the Box object stays the same, and its size increases to the left and right by the dx value, to the top and the bottom by the dy value, and to the front and the back by the dz value.

    Parameters

    • dx: number

      The value to be added to the left and the right of the Box object. The following equation is used to calculate the new width and position of the box:

    • dy: number

      The value to be added to the top and the bottom of the Box object. The following equation is used to calculate the new height and position of the box:

    • dz: number

      The value to be added to the front and the back of the Box object. The following equation is used to calculate the new depth and position of the box:

    Returns void

inflatePoint

  • Increases the size of the Box object. This method is similar to the Box.inflate() method except it takes a Vector3D object as a parameter.

    The following two code examples give the same result:

    Parameters

    • delta: Vector3D

      The x property of this Vector3D object is used to increase the horizontal dimension of the Box object. The y property is used to increase the vertical dimension of the Box object. The z property is used to increase the longitudinal dimension of the Box object.

    Returns void

intersection

  • intersection(toIntersect: Box): Box
  • If the Box object specified in the toIntersect parameter intersects with this Box object, returns the area of intersection as a Box object. If the boxes do not intersect, this method returns an empty Box object with its properties set to 0.

    Parameters

    • toIntersect: Box

      The Box object to compare against to see if it intersects with this Box object.

    Returns Box

    A Box object that equals the area of intersection. If the boxes do not intersect, this method returns an empty Box object; that is, a box with its x, y, z, width, height, and depth properties set to 0.

intersects

  • intersects(toIntersect: Box): boolean
  • Determines whether the object specified in the toIntersect parameter intersects with this Box object. This method checks the x, y, z, width, height, and depth properties of the specified Box object to see if it intersects with this Box object.

    Parameters

    • toIntersect: Box

      The Box object to compare against this Box object.

    Returns boolean

    A value of true if the specified object intersects with this Box object; otherwise false.

isEmpty

  • isEmpty(): boolean
  • Determines whether or not this Box object is empty.

    Returns boolean

    A value of true if the Box object's width, height or depth is less than or equal to 0; otherwise false.

offset

  • offset(dx: number, dy: number, dz: number): void
  • Adjusts the location of the Box object, as determined by its top-left-front corner, by the specified amounts.

    Parameters

    • dx: number

      Moves the x value of the Box object by this amount.

    • dy: number

      Moves the y value of the Box object by this amount.

    • dz: number

      Moves the z value of the Box object by this amount.

    Returns void

offsetPosition

  • offsetPosition(position: Vector3D): void
  • Adjusts the location of the Box object using a Vector3D object as a parameter. This method is similar to the Box.offset() method, except that it takes a Vector3D object as a parameter.

    Parameters

    • position: Vector3D

      A Vector3D object to use to offset this Box object.

    Returns void

rayIntersection

setEmpty

  • setEmpty(): void
  • Sets all of the Box object's properties to 0. A Box object is empty if its width, height or depth is less than or equal to 0.

    This method sets the values of the x, y, z, width, height, and depth properties to 0.

    Returns void

setTo

  • setTo(xa: number, ya: number, za: number, widtha: number, heighta: number, deptha: number): void
  • Sets the members of Box to the specified values

    Parameters

    • xa: number

      The x coordinate of the top-left-front corner of the box.

    • ya: number

      The y coordinate of the top-left-front corner of the box.

    • za: number
    • widtha: number

      The width of the box, in pixels.

    • heighta: number

      The height of the box, in pixels.

    • deptha: number

      The depth of the box, in pixels.

    Returns void

toString

  • toString(): string
  • Builds and returns a string that lists the horizontal, vertical and longitudinal positions and the width, height and depth of the Box object.

    Returns string

    A string listing the value of each of the following properties of the Box object: x, y, z, width, height, and depth.

union

  • Adds two boxes together to create a new Box object, by filling in the horizontal, vertical and longitudinal space between the two boxes.

    Note: The union() method ignores boxes with 0 as the height, width or depth value, such as: var box2:Box = new Box(300,300,300,50,50,0);

    Parameters

    • toUnion: Box

      A Box object to add to this Box object.

    • Default value target: Box = null

    Returns Box

    A new Box object that is the union of the two boxes.

Generated using TypeDoc