LogoPixi’VN
pixi-jsClasses

Class: Ellipse

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:28

The Ellipse object is used to help draw graphics and can also be used to specify a hit area for containers.

Example

// Basic ellipse creation
const ellipse = new Ellipse(100, 100, 20, 10);

// Use as a hit area
container.hitArea = new Ellipse(0, 0, 50, 25);

// Check point containment
const isInside = ellipse.contains(mouseX, mouseY);

// Get bounding box
const bounds = ellipse.getBounds();

Remarks

  • Defined by center (x,y) and half dimensions
  • Total width = halfWidth * 2
  • Total height = halfHeight * 2

See

Standard

Implements

Constructors

Constructor

> new Ellipse(x?, y?, halfWidth?, halfHeight?): Ellipse

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:97

Parameters

x?

number

The X coordinate of the center of this ellipse

y?

number

The Y coordinate of the center of this ellipse

halfWidth?

number

The half width of this ellipse

halfHeight?

number

The half height of this ellipse

Returns

Ellipse

Properties

halfHeight

> halfHeight: number

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:72

The half height of this ellipse

Example

// Set half height
const ellipse = new Ellipse(100, 100);
ellipse.halfHeight = 25; // Total height will be 50

Default

0

halfWidth

> halfWidth: number

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:61

The half width of this ellipse

Example

// Set half width
const ellipse = new Ellipse(100, 100);
ellipse.halfWidth = 50; // Total width will be 100

Default

0

type

> readonly type: "ellipse" = "ellipse"

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:90

The type of the object, mainly used to avoid instanceof checks

Example

// Check shape type
const shape = new Ellipse(0, 0, 50, 25);
console.log(shape.type); // 'ellipse'

// Use in type guards
if (shape.type === 'ellipse') {
    console.log(shape.halfWidth, shape.halfHeight);
}

Default

'ellipse'

See

SHAPE_PRIMITIVE For all shape types

Implementation of

ShapePrimitive.type


x

> x: number

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:39

The X coordinate of the center of this ellipse

Example

// Basic x position
const ellipse = new Ellipse();
ellipse.x = 100;

Default

0

Implementation of

ShapePrimitive.x


y

> y: number

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:50

The Y coordinate of the center of this ellipse

Example

// Basic y position
const ellipse = new Ellipse();
ellipse.y = 200;

Default

0

Implementation of

ShapePrimitive.y

Methods

clone()

> clone(): Ellipse

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:119

Creates a clone of this Ellipse instance.

Returns

Ellipse

A copy of the ellipse

Example

// Basic cloning
const original = new Ellipse(100, 100, 50, 25);
const copy = original.clone();

// Clone and modify
const modified = original.clone();
modified.halfWidth *= 2;
modified.halfHeight *= 2;

// Verify independence
console.log(original.halfWidth);  // 50
console.log(modified.halfWidth);  // 100

See

Implementation of

ShapePrimitive.clone


contains()

> contains(x, y): boolean

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:139

Checks whether the x and y coordinates given are contained within this ellipse. Uses normalized coordinates and the ellipse equation to determine containment.

Parameters

x

number

The X coordinate of the point to test

y

number

The Y coordinate of the point to test

Returns

boolean

Whether the x/y coords are within this ellipse

Example

// Basic containment check
const ellipse = new Ellipse(100, 100, 50, 25);
const isInside = ellipse.contains(120, 110);

Remarks

  • Uses ellipse equation (x²/a² + y²/b² ≤ 1)
  • Returns false if dimensions are 0 or negative
  • Normalized to center (0,0) for calculation

See

Implementation of

ShapePrimitive.contains


copyFrom()

> copyFrom(ellipse): this

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:204

Copies another ellipse to this one.

Parameters

ellipse

Ellipse

The ellipse to copy from

Returns

this

Returns itself

Example

// Basic copying
const source = new Ellipse(100, 100, 50, 25);
const target = new Ellipse();
target.copyFrom(source);

See

Implementation of

ShapePrimitive.copyFrom


copyTo()

> copyTo(ellipse): Ellipse

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:219

Copies this ellipse to another one.

Parameters

ellipse

Ellipse

The ellipse to copy to

Returns

Ellipse

Returns given parameter

Example

// Basic copying
const source = new Ellipse(100, 100, 50, 25);
const target = new Ellipse();
source.copyTo(target);

See

Implementation of

ShapePrimitive.copyTo


getBounds()

> getBounds(out?): Rectangle

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:189

Returns the framing rectangle of the ellipse as a Rectangle object.

Parameters

out?

Rectangle

Optional Rectangle object to store the result

Returns

Rectangle

The framing rectangle

Example

// Basic bounds calculation
const ellipse = new Ellipse(100, 100, 50, 25);
const bounds = ellipse.getBounds();
// bounds: x=50, y=75, width=100, height=50

// Reuse existing rectangle
const rect = new Rectangle();
ellipse.getBounds(rect);

Remarks

  • Creates Rectangle if none provided
  • Top-left is (x-halfWidth, y-halfHeight)
  • Width is halfWidth * 2
  • Height is halfHeight * 2

See

Implementation of

ShapePrimitive.getBounds


strokeContains()

> strokeContains(x, y, strokeWidth, alignment?): boolean

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:165

Checks whether the x and y coordinates given are contained within this ellipse including stroke.

Parameters

x

number

The X coordinate of the point to test

y

number

The Y coordinate of the point to test

strokeWidth

number

The width of the line to check

alignment?

number

The alignment of the stroke (1 = inner, 0.5 = centered, 0 = outer)

Returns

boolean

Whether the x/y coords are within this ellipse's stroke

Example

// Basic stroke check
const ellipse = new Ellipse(100, 100, 50, 25);
const isOnStroke = ellipse.strokeContains(150, 100, 4); // 4px line width

// Check with different alignments
const innerStroke = ellipse.strokeContains(150, 100, 4, 1);   // Inside
const centerStroke = ellipse.strokeContains(150, 100, 4, 0.5); // Centered
const outerStroke = ellipse.strokeContains(150, 100, 4, 0);   // Outside

Remarks

  • Uses normalized ellipse equations
  • Considers stroke alignment
  • Returns false if dimensions are 0

See

Implementation of

ShapePrimitive.strokeContains


toString()

> toString(): string

Defined in: node_modules/pixi.js/lib/maths/shapes/Ellipse.d.ts:220

Returns a string representation of an object.

Returns

string