This document describes how to use the ShapeInfo class to describe shapes for intersection. This class is built up of the following shape creation methods:
- ShapeInfo.arc(...)
- ShapeInfo.quadraticBezier(...)
- ShapeInfo.cubicBezier(...)
- ShapeInfo.circle(...)
- ShapeInfo.ellipse(...)
- ShapeInfo.line(...)
- ShapeInfo.path(...)
- ShapeInfo.polygon(...)
- ShapeInfo.polyline(...)
- ShapeInfo.rectangle(...)
In place of ..., you can pass in one of the following:
- An object describing the shape
- An array describing the shape
- A list of arguments, describing the shape. This is the same as the array format; however, the array's elements are spread into the method call.
Each section below gives a description of the various formats that may be used to describe a given shape type.
An arc is defined by:
- A center point
- An x radius and a y radius
- A start angle
- An end angle
The center may be represented four ways:
- A
center
property that is an object withx
andy
number properties - A
center
property that is an array with two number elements,x
being the first element andy
being the second element - A
cx
number property and acy
number property - A
centerX
number property and acenterY
number property
const centers = [
{center: new Point2D(10, 20)},
{center: {x: 10, y: 20}},
{center: [10, 20]},
{cx: 10, cy: 20},
{centerX: 10, centerY: 20}
];
The radii may be represented four ways:
- A
radii
property that is an object withx
andy
number properties - A
radii
property that is an array with two number elements,rx
being the first element andry
being the second element - An
rx
number property and anry
number property - A
radiusX
number property and aradiusY
number property
const radii = [
{radii: {x: 5, y: 10}},
{radii: [5, 10]},
{rx: 5, ry: 10},
{radiusX: 5, radiusY: 10}
];
The starting angle is a startAngle
number property. This value is measured in radians.
The ending angle is a endAngle
number property. This value is measured in radians.
The above discussed how an object may be used to describe an Arc. For backward compatibility with older shapes APIs, it is also possible to pass an array or a list of arguments.
There are two supported formats:
- A 6 element array defined as follows:
- a number element being
centerX
- a number element being
centerY
- a number element being
radiusX
- a number element being
radiusY
- a number element being
startRadians
- a number element being
endRadians
- a number element being
- A 5 element array defined as follows:
- an object with
x
andy
number properties being thecenter
- a number element being
radiusX
- a number element being
radiusY
- a number element being
startRadians
- a number element being
endRadians
- an object with
Note that these examples are not exhaustive. You may combine the above descriptions in any way you wish.
const arcs = [
ShapeInfo.arc({center: {x: 10, y: 20}, radii: {x: 5, y: 10}, startAngle: 0, endAngle: Math.PI}),
ShapeInfo.arc({center: [10, 20], radii: [5, 10], startAngle: 0, endAngle: Math.PI}),
ShapeInfo.arc({cx: 10, cy: 20, rx: 5, ry: 10, startAngle: 0, endAngle: Math.PI}),
ShapeInfo.arc({centerX: 10, centerY: 20, radiusX: 5, radiusY: 10, startAngle: 0, endAngle: Math.PI}),
ShapeInfo.arc([10, 20, 5, 10, 0, Math.PI]),
ShapeInfo.arc([{x: 10, y: 20}, 5, 10, 0, Math.PI]),
ShapeInfo.arc(10, 20, 5, 10, 0, Math.PI),
ShapeInfo.arc({x: 10, y: 20}, 5, 10, 0, Math.PI)
];
A quadratic bezier is defined by:
- 3 control points: p1, p2, and p3
A control point may be represented two ways:
- An object with
x
andy
number properties - An array with two number elements,
x
being the first element andy
being the second element
const points = [
{p1: new Point2D(10, 20)},
{p2: {x: 10, y: 20}},
{p3: [10, 20]}
];
The above discussed how an object may be used to describe a Quadratic Bezier. For backward compatibility with older shapes APIs, it is also possible to pass an array or a list of arguments.
There are two supported formats:
- A 6 element array defined as follows:
- a number element being
p1.x
- a number element being
p1.y
- a number element being
p2.x
- a number element being
p2.y
- a number element being
p3.x
- a number element being
p3.y
- a number element being
- A 3 element array defined as follows:
- an object with
x
andy
number properties beingp1
- an object with
x
andy
number properties beingp2
- an object with
x
andy
number properties beingp3
- an object with
Note that these examples are not exhaustive. You may combine the above descriptions in any way you wish.
const beziers = [
ShapeInfo.quadraticBezier({p1: {x: 10, y: 20}, p2: {x: 5, y: 10}, p3: {x: 15, y: 30}}),
ShapeInfo.quadraticBezier({p1: [10, 20], p2: [5, 10], p3: [15, 30]}),
ShapeInfo.quadraticBezier([10, 20, 5, 10, 15, 30]),
ShapeInfo.quadraticBezier([{x: 10, y: 20}, {x: 5, y: 10}, {x: 15, y: 30}]),
ShapeInfo.quadraticBezier(10, 20, 5, 10, 15, 30),
ShapeInfo.quadraticBezier({x: 10, y: 20}, {x: 5, y: 10}, {x: 15, y: 30})
];
A cubic bezier is defined by:
- 4 control points: p1, p2, p3, and p4
A control point may be represented two ways:
- An object with
x
andy
number properties - An array with two number elements,
x
being the first element andy
being the second element
const points = [
{p1: new Point2D(10, 20)},
{p2: {x: 10, y: 20}},
{p3: [10, 20]}
];
The above discussed how an object may be used to describe a Quadratic Bezier. For backward compatibility with older shapes APIs, it is also possible to pass an array or a list of arguments.
There are two supported formats:
- A 8 element array defined as follows:
- a number element being
p1.x
- a number element being
p1.y
- a number element being
p2.x
- a number element being
p2.y
- a number element being
p3.x
- a number element being
p3.y
- a number element being
p4.x
- a number element being
p4.y
- a number element being
- A 4 element array defined as follows:
- an object with
x
andy
number properties beingp1
- an object with
x
andy
number properties beingp2
- an object with
x
andy
number properties beingp3
- an object with
x
andy
number properties beingp4
- an object with
Note that these examples are not exhaustive. You may combine the above descriptions in any way you wish.
const beziers = [
ShapeInfo.cubicBezier({p1: {x: 10, y: 20}, p2: {x: 5, y: 10}, p3: {x: 15, y: 30}, p4: {x: 20, y: 15}}),
ShapeInfo.cubicBezier({p1: [10, 20], p2: [5, 10], p3: [15, 30], p4: [20, 15]}),
ShapeInfo.cubicBezier([10, 20, 5, 10, 15, 30, 20, 15]),
ShapeInfo.cubicBezier([{x: 10, y: 20}, {x: 5, y: 10}, {x: 15, y: 30}, {x: 20, y: 15}]),
ShapeInfo.cubicBezier(10, 20, 5, 10, 15, 30, 20, 15),
ShapeInfo.cubicBezier({x: 10, y: 20}, {x: 5, y: 10}, {x: 15, y: 30}, {x: 20, y: 15})
];
An circle is defined by:
- A center point
- A radius
The center may be represented four ways:
- A
center
property that is an object withx
andy
number properties - A
center
property that is an array with two number elements,x
being the first element andy
being the second element - A
cx
number property and acy
number property - A
centerX
number property and acenterY
number property
const centers = [
{center: new Point2D(10, 20)},
{center: {x: 10, y: 20}},
{center: [10, 20]},
{cx: 10, cy: 20},
{centerX: 10, centerY: 20}
];
The radius may be represented two ways:
- An
r
number property - A
radius
number
const radii = [
{r: 5},
{radius: 5}
];
The above discussed how an object may be used to describe an Circle. For backward compatibility with older shapes APIs, it is also possible to pass an array or a list of arguments.
There are two supported formats:
- A 3 element array defined as follows:
- a number element being
centerX
- a number element being
centerY
- a number element being
radius
- a number element being
- A 2 element array defined as follows:
- an object with
x
andy
number properties being thecenter
- a number element being
radius
- an object with
Note that these examples are not exhaustive. You may combine the above descriptions in any way you wish.
const circles = [
ShapeInfo.circle({center: {x: 10, y: 20}, radius: 15}),
ShapeInfo.circle({center: [10, 20], radius: 15}),
ShapeInfo.circle({cx: 10, cy: 20, r: 15}),
ShapeInfo.circle({centerX: 10, centerY: 20, radius: 15}),
ShapeInfo.circle([10, 20, 15]),
ShapeInfo.circle([{x: 10, y: 20}, 15]),
ShapeInfo.circle(10, 20, 15),
ShapeInfo.circle({x: 10, y: 20}, 15)
];
An ellipse is defined by:
- A center point
- An x radius and a y radius
The center may be represented four ways:
- A
center
property that is an object withx
andy
number properties - A
center
property that is an array with two number elements,x
being the first element andy
being the second element - A
cx
number property and acy
number property - A
centerX
number property and acenterY
number property
const centers = [
{center: new Point2D(10, 20)},
{center: {x: 10, y: 20}},
{center: [10, 20]},
{cx: 10, cy: 20},
{centerX: 10, centerY: 20}
];
The radii may be represented four ways:
- A
radii
property that is an object withx
andy
number properties - A
radii
property that is an array with two number elements,rx
being the first element andry
being the second element - An
rx
number property and anry
number property - A
radiusX
number property and aradiusY
number property
const radii = [
{radii: {x: 5, y: 10}},
{radii: [5, 10]},
{rx: 5, ry: 10},
{radiusX: 5, radiusY: 10}
];
The above discussed how an object may be used to describe an Ellipse. For backward compatibility with older shapes APIs, it is also possible to pass an array or a list of arguments.
There are two supported formats:
- A 4 element array defined as follows:
- a number element being
centerX
- a number element being
centerY
- a number element being
radiusX
- a number element being
radiusY
- a number element being
- A 3 element array defined as follows:
- an object with
x
andy
number properties being thecenter
- a number element being
radiusX
- a number element being
radiusY
- an object with
Note that these examples are not exhaustive. You may combine the above descriptions in any way you wish.
const ellipses = [
ShapeInfo.ellipse({center: {x: 10, y: 20}, radii: {x: 5, y: 10}}),
ShapeInfo.ellipse({center: [10, 20], radii: [5, 10]}),
ShapeInfo.ellipse({cx: 10, cy: 20, rx: 5, ry: 10}),
ShapeInfo.ellipse({centerX: 10, centerY: 20, radiusX: 5, radiusY: 10}),
ShapeInfo.ellipse([10, 20, 3, 5]),
ShapeInfo.ellipse([{x: 10, y: 20}, 3, 5]),
ShapeInfo.ellipse(10, 20, 3, 5),
ShapeInfo.ellipse({x: 10, y: 20}, 3, 5)
];
A line is defined by:
- 2 points: p1 and p2
A point may be represented two ways:
- An object with
x
andy
number properties - An array with two number elements,
x
being the first element andy
being the second element
const points = [
{p1: new Point2D(10, 20)},
{p2: {x: 10, y: 20}},
{p1: [10, 20]}
];
The above discussed how an object may be used to describe a Quadratic Bezier. For backward compatibility with older shapes APIs, it is also possible to pass an array or a list of arguments.
There are two supported formats:
- A 4 element array defined as follows:
- a number element being
p1.x
- a number element being
p1.y
- a number element being
p2.x
- a number element being
p2.y
- a number element being
- A 2 element array defined as follows:
- an object with
x
andy
number properties beingp1
- an object with
x
andy
number properties beingp2
- an object with
Note that these examples are not exhaustive. You may combine the above descriptions in any way you wish.
const lines = [
ShapeInfo.line({p1: {x: 10, y: 20}, p2: {x: 5, y: 10}}),
ShapeInfo.line({p1: [10, 20], p2: [5, 10]}),
ShapeInfo.line([10, 20, 5, 10]),
ShapeInfo.line([{x: 10, y: 20}, {x: 5, y: 10}]),
ShapeInfo.line(10, 20, 5, 10),
ShapeInfo.line({x: 10, y: 20}, {x: 5, y: 10})
];
A path is defined by:
- Path data
Path data is a string following the path syntax as defined by the SVG Specification.
const paths = [
ShapeInfo.path("M0,0 L100,100")
];
A polygon is defined by
- An array of zero or points
A point may be represented two ways:
- An object with
x
andy
number properties - An array with two number elements,
x
being the first element andy
being the second element
Each of these representations is concatenated into a single array.
const polygons = [
ShapeInfo.polygon([10, 20, 30, 40, 50, 60]),
ShapeInfo.polygon([{x: 10, y: 20}, {x: 30, y: 40}, {x: 50, y: 60}])
];
A polyline is defined by
- An array of zero or points
A point may be represented two ways:
- An object with
x
andy
number properties - An array with two number elements,
x
being the first element andy
being the second element
Each of these representations is concatenated into a single array.
const polylines = [
ShapeInfo.polyline([10, 20, 30, 40, 50, 60]),
ShapeInfo.polyline([{x: 10, y: 20}, {x: 30, y: 40}, {x: 50, y: 60}])
];
A rectangle is defined by:
- A topLeft point
- A bottomRight point
- Optional x and y radii
A point and a vector may be represented two ways:
- An object with
x
andy
number properties - An array with two number elements,
x
being the first element andy
being the second element
The topLeft
point may be represented four ways:
- An object with a
topLeft
property that is a point as an object - An object with a
topLeft
property that is a point as an array - An object with a
x
number property and ay
number property - An object with a
top
number property and aleft
number property
The bottomRight
point may be represented six ways:
- An object with a
bottomRight
property that is a point as an object - An object with a
bottomRight
property that is a point as an array - An object with a
w
number property and ah
number property - An object with a
width
number property and aheight
number property - An object with a
size
property that is a vector as an object - An object with a
size
property that is a vector as an array
const points = [
{topLeft: {x: 10, y: 20}, bottomRight: {x: 30, y: 40}},
{topLeft: [10, 20], bottomRight: [30, 40]},
{x: 10, y: 20, w: 20, h: 20},
{top: 20, left: 10, width: 20, height: 20},
{topLeft: {x: 10, y: 20}, size: {x: 20, y: 20}},
{topLeft: [10, 20], size: [20, 20]}
];
The x radius may be represented two ways:
- An
rx
number property - A
radiusX
number property
- An
ry
number property - A
radiusY
number property
The above discussed how an object may be used to describe a Quadratic Bezier. For backward compatibility with older shapes APIs, it is also possible to pass an array or a list of arguments.
There are five supported formats:
- A 4 element array defined as follows:
- a number element being
x
- a number element being
y
- a number element being
width
- a number element being
height
- a number element being
- A 6 element array defined as follows:
- a number element being
x
- a number element being
y
- a number element being
width
- a number element being
height
- a number element being
rx
- a number element being
ry
- a number element being
- A 2 element array defined as follows:
- an object with
x
andy
number properties beingtopLeft
- an object with
x
andy
number properties beingsize
(width, height)
- an object with
- A 3 element array defined as follows:
- an object with
x
andy
number properties beingtopLeft
- an object with
x
andy
number properties beingsize
(width, height) - an object with
rx
andry
number properties beingradii
- an object with
- A 3 element array defined as follows:
- an object with
x
andy
number properties beingtopLeft
- an object with
x
andy
number properties beingsize
(width, height) - an object with
radiusX
andradiusY
number properties beingradii
- an object with
Note that these examples are not exhaustive. You may combine the above descriptions in any way you wish.
const rectangles = [
ShapeInfo.rectangle({topLeft: {x: 10, y: 20}, bottomRight: {x: 5, y: 10}}),
ShapeInfo.rectangle({topLeft: {x: 10, y: 20}, bottomRight: {x: 5, y: 10}, radiusX: 10, radiusY: 15}),
ShapeInfo.rectangle({topLeft: [10, 20], bottomRight: [5, 10]}),
ShapeInfo.rectangle({topLeft: [10, 20], bottomRight: [5, 10], radiusX: 10, radiusY: 15}),
ShapeInfo.rectangle({top: 20, left: 10, width: 5, height: 10}),
ShapeInfo.rectangle({x: 10, y: 20, w: 5, h: 10, rx: 10, ry: 15}),
ShapeInfo.rectangle([10, 20, 5, 10, 10, 15]),
ShapeInfo.rectangle(10, 20, 5, 10, 10, 15)
];