The X coordinate of the center of this ellipse
The Y coordinate of the center of this ellipse
The half width of this ellipse
The half height of this ellipse
The half height of this ellipse
The half width of this ellipse
Readonly
typeThe type of the object, mainly used to avoid instanceof
checks
// 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);
}
SHAPE_PRIMITIVE For all shape types
The X coordinate of the center of this ellipse
The Y coordinate of the center of this ellipse
Creates a clone of this Ellipse instance.
A copy of the ellipse
// 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
Checks whether the x and y coordinates given are contained within this ellipse. Uses normalized coordinates and the ellipse equation to determine containment.
The X coordinate of the point to test
The Y coordinate of the point to test
Whether the x/y coords are within this ellipse
// Basic containment check
const ellipse = new Ellipse(100, 100, 50, 25);
const isInside = ellipse.contains(120, 110);
Copies another ellipse to this one.
The ellipse to copy from
Returns itself
// Basic copying
const source = new Ellipse(100, 100, 50, 25);
const target = new Ellipse();
target.copyFrom(source);
Copies this ellipse to another one.
The ellipse to copy to
Returns given parameter
// Basic copying
const source = new Ellipse(100, 100, 50, 25);
const target = new Ellipse();
source.copyTo(target);
Returns the framing rectangle of the ellipse as a Rectangle object.
Optional
out: RectangleOptional Rectangle object to store the result
The framing rectangle
// 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);
Checks whether the x and y coordinates given are contained within this ellipse including stroke.
The X coordinate of the point to test
The Y coordinate of the point to test
The width of the line to check
The alignment of the stroke (1 = inner, 0.5 = centered, 0 = outer)
Whether the x/y coords are within this ellipse's stroke
// 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
Returns a string representation of an object.
The Ellipse object is used to help draw graphics and can also be used to specify a hit area for containers.
Example
Remarks
See