BoundingCircle

View source

Represents a circular 2D bounds value for circle-shaped regions.

Use BoundingCircle as a standalone geometry value when an API needs a circle-shaped region. Use intersectCircle or intersectAABB2DvsCircle to test overlap with another geometry value.

BoundingCircle#translate changes the current center in place. The static translation helper can write a center into a supplied output value, while BoundingCircle.copy copies the center and radius. Serialization stores only the persisted geometry; the runtime type discriminator is supplied by construction and is not serialized.

Examples

import { BoundingCircle, intersectCircle } from '@wimaengine/geometry'

const region = new BoundingCircle(10, 20, 5)
region.translate(2, -1)
const copy = BoundingCircle.copy(region)
console.log(intersectCircle(region, copy)) // true

Constructor


constructor(x?: number, y?: number, r?: number)

View source

Creates a circular bound with a center and radius.

Parameters

NameDescriptionDefault
x?

Center x-coordinate.

0
y?

Center y-coordinate.

0
r?

Radius.

0

Properties


readonlytype: number

View source

Bound discriminator for circular geometry.

Default: BoundType.Circle

Methods


translate(x: number, y: number): void

View source

Translates this circle’s center in place.

The radius and type discriminator are unchanged. This instance method returns no value; use BoundingCircle.translate when a returned output value is preferred.

Parameters

NameDescriptionDefault
x

Offset to add to the center’s x-coordinate.

—
y

Offset to add to the center’s y-coordinate.

—

copy(bound: BoundingCircle): void

View source

Copies another circle’s center and radius into this instance.

The type discriminator is left unchanged. This instance method returns no value; use BoundingCircle.copy when a returned output value is preferred.

Parameters

NameDescriptionDefault
bound

Source circle.

—

statictranslate(bound: BoundingCircle, x: number, y: number, out?: BoundingCircle): BoundingCircle

View source

Writes a translated center into an output circle.

Only the output position is changed; the source radius and type are not copied. Pass an existing output to update it in place, or omit out to receive a new BoundingCircle with the translated center.

Parameters

NameDescriptionDefault
bound

Source circle whose center is translated.

—
x

Offset to add to the center’s x-coordinate.

—
y

Offset to add to the center’s y-coordinate.

—
out?

Circle whose position is updated.

...

Returns

The updated output circle.

staticcopy(bound: BoundingCircle, out?: BoundingCircle): BoundingCircle

View source

Copies a circle’s center and radius to an output circle.

The destination’s type discriminator is preserved. When out is omitted, a new circular bound is created and returned.

Parameters

NameDescriptionDefault
bound

Source circle.

—
out?

Circle to update in place.

...

Returns

The updated output circle.

staticserialize(value: BoundingCircle): BoundingCircleSerial

View source

Converts a circle to its serializable radius and position.

The returned object contains r and the serialized pos; it does not contain the type discriminator.

Parameters

NameDescriptionDefault
value

Circle to serialize.

—

Returns

Serialized circle data.

staticdeserialize(value: BoundingCircleSerial, out?: BoundingCircle): BoundingCircle

View source

Restores a circle from serialized radius and position data.

When out is supplied, its radius and position are updated in place and its type discriminator is preserved. Otherwise a new circle is returned.

Parameters

NameDescriptionDefault
value

Serialized circle data.

—
out?

Circle to update in place.

...

Returns

The restored circle.

staticvalidateSerial(value: unknown): value is BoundingCircleSerial

View source

Checks whether a value has the serialized circle shape.

Validation requires a non-null object with numeric r and valid vector data in pos. It does not require or validate the type discriminator, and it does not enforce a radius range or finiteness.

Parameters

NameDescriptionDefault
value

Value to validate.

—

Returns

Whether the value is valid serialized data.