Mathematical utilities.
- Copyright:
- 2010 Alexis Deveria, 2010 Jeff Schiller
- License:
- MIT
- Source:
Methods
(static) getMatrix(elem) → {SVGMatrix}
Get the matrix object for a given element.
Parameters:
| Name | Type | Description |
|---|---|---|
elem |
Element | The DOM element to check |
- Source:
Returns:
The matrix object associated with the element's transformlist
- Type
- SVGMatrix
(static) hasMatrixTransform(tlistopt) → {boolean}
See if the given transformlist includes a non-indentity matrix transform.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tlist |
SVGTransformList |
<optional> |
The transformlist to check |
- Source:
Returns:
Whether or not a matrix transform was found
- Type
- boolean
(static) isIdentity(m) → {boolean}
Helper function to check if the matrix performs no actual transform (i.e. exists for identity purposes).
Parameters:
| Name | Type | Description |
|---|---|---|
m |
SVGMatrix | The matrix object to check |
- Source:
Returns:
Indicates whether or not the matrix is 1,0,0,1,0,0
- Type
- boolean
(static) matrixMultiply(…args) → {SVGMatrix}
This function tries to return a SVGMatrix that is the multiplication m1 * m2.
We also round to zero when it's near zero.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
SVGMatrix |
<repeatable> |
Matrix objects to multiply |
- Source:
Returns:
The matrix object resulting from the calculation
- Type
- SVGMatrix
(static) rectsIntersect(r1, r2) → {boolean}
Check if two rectangles (BBoxes objects) intersect each other.
Parameters:
| Name | Type | Description |
|---|---|---|
r1 |
SVGRect | The first BBox-like object |
r2 |
SVGRect | The second BBox-like object |
- Source:
Returns:
True if rectangles intersect
- Type
- boolean
(static) snapToAngle(x1, y1, x2, y2) → {module:math.AngleCoord45}
Returns a 45 degree angle coordinate associated with the two given coordinates.
Parameters:
| Name | Type | Description |
|---|---|---|
x1 |
Integer | First coordinate's x value |
y1 |
Integer | First coordinate's y value |
x2 |
Integer | Second coordinate's x value |
y2 |
Integer | Second coordinate's y value |
- Source:
Returns:
(static) transformBox(l, t, w, h, m) → {module:math.TransformedBox}
Transforms a rectangle based on the given matrix.
Parameters:
| Name | Type | Description |
|---|---|---|
l |
Float | Float with the box's left coordinate |
t |
Float | Float with the box's top coordinate |
w |
Float | Float with the box width |
h |
Float | Float with the box height |
m |
SVGMatrix | Matrix object to transform the box by |
- Source:
Returns:
(static) transformListToTransform(tlist, minopt, maxopt) → {SVGTransform}
This returns a single matrix Transform for a given Transform List
(this is the equivalent of SVGTransformList.consolidate() but unlike
that method, this one does not modify the actual SVGTransformList).
This function is very liberal with its min, max arguments.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
tlist |
SVGTransformList | The transformlist object |
||
min |
Integer |
<optional> |
0 | Optional integer indicating start transform position |
max |
Integer |
<optional> |
Optional integer indicating end transform position;
defaults to one less than the tlist's |
- Source:
Returns:
A single matrix transform object
- Type
- SVGTransform
(static) transformPoint(x, y, m) → {module:math.XYObject}
A (hopefully) quicker function to transform a point by a matrix (this function avoids any DOM calls and just does the math).
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Float | Float representing the x coordinate |
y |
Float | Float representing the y coordinate |
m |
SVGMatrix | Matrix object to transform the point with |
- Source:
Returns:
An x, y object representing the transformed point
- Type
- module:math.XYObject
Type Definitions
AngleCoord45
Type:
Properties:
| Name | Type | Description |
|---|---|---|
x |
Float | The angle-snapped x value |
y |
Float | The angle-snapped y value |
a |
Integer | The angle at which to snap |
- Source:
TransformedBox
An object with the following values
Type:
Properties:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tl |
module:math.XYObject | The top left coordinate |
|||||||||||||||
tr |
module:math.XYObject | The top right coordinate |
|||||||||||||||
bl |
module:math.XYObject | The bottom left coordinate |
|||||||||||||||
br |
module:math.XYObject | The bottom right coordinate |
|||||||||||||||
aabox |
PlainObject | Object with the following values: Properties
|
- Source:
XYObject
Type:
Properties:
| Name | Type | Description |
|---|---|---|
x |
Float | |
y |
Float |
- Source: