GeezerVison is showing drafts.csswg.org — Geometry Interfaces Module Level 1
1. Introduction
This section is non-normative.
This specification describes several geometry interfaces for the representation of points,
rectangles, quadrilaterals and transformation matrices with the dimension of 3x2 and 4x4.
The following algorithms assume that DOMPointReadOnly objects have the internal member
variables x coordinate, y coordinate, z
coordinate and w perspective.
DOMPointReadOnly as well as the inheriting interface DOMPoint must be able to access and set
the value of these variables.
An interface returning an DOMPointReadOnly object by an attribute or function may be able to
modify internal member variable values. Such an interface must specify this ability explicitly in
prose.
Internal member variables must not be exposed in any way.
The DOMPointReadOnly(x,
y, z, w) and DOMPoint(x, y, z, w)
constructors, when invoked, must run the following steps:
The x attribute, on getting, must return the x
coordinate value. For the DOMPoint interface, setting the
x attribute must set the x coordinate to the new value.
The y attribute, on getting, must return the y
coordinate value. For the DOMPoint interface, setting the
y attribute must set the y coordinate to the new value.
The z attribute, on getting, must return the z
coordinate value. For the DOMPoint interface, setting the
z attribute must set the z coordinate to the new value.
The w attribute, on getting, must return the w
perspective value. For the DOMPoint interface, setting the
w attribute must set the w perspective to the new value.
The matrixTransform(matrix)
method, when invoked, must run the following steps:
var point =new DOMPoint(5,4);var matrix =new DOMMatrix([2,0,0,2,10,10]);var transformedPoint = point.matrixTransform(matrix);
The point variable is set to a new DOMPoint object with x
coordinate initialized to 5 and y coordinate initialized to 4. This new
DOMPoint is now scaled and the translated by matrix. This resulting transformedPoint has the x coordinate 20 and y
coordinate 18.
Set transformedPoint’s x coordinate to pointVector’s
first element.
Set transformedPoint’s y coordinate to pointVector’s
second element.
Set transformedPoint’s z coordinate to pointVector’s
third element.
Set transformedPoint’s w perspective to pointVector’s
fourth element.
Return transformedPoint.
Note: If matrix’s is 2D is true, point’s z coordinate is 0 or -0, and point’s w perspective
is 1, then this is a 2D transformation. Otherwise this is a 3D transformation.
3. The DOMRect interfaces
Objects implementing the DOMRectReadOnly interface represent a rectangle.
When the rectangle has a non-negative width dimension, the rectangle’s
horizontal origin is the left edge; otherwise, it is the right edge. Similarly, when the rectangle
has a non-negative height dimension, the rectangle’s vertical origin is the
top edge; otherwise, it is the bottom edge.
x coordinate
The horizontal distance between the viewport’s left edge and the rectangle’s origin.
y coordinate
The vertical distance between the viewport’s top edge and the rectangle’s origin.
An interface returning an DOMRectReadOnly object by an attribute or function may be able to
modify internal member variable values. Such an interface must specify this ability explicitly in
prose.
Internal member variables must not be exposed in any way.
The DOMRectReadOnly(x,
y, width, height) and DOMRect(x, y, width,
height) constructors, when invoked, must run the following steps:
The x attribute, on getting, must return the x
coordinate value. For the DOMRect interface, setting the
x attribute must set the x coordinate to the new value.
The y attribute, on getting, it must return the y
coordinate value. For the DOMRect interface, setting the
y attribute must set the y coordinate to the new value.
The width attribute, on getting, must return the width
dimension value. For the DOMRect interface, setting the
width attribute must set the width dimension to the new value.
The height attribute, on getting, must return the height dimension value. For the DOMRect interface, setting the
height attribute must set the height dimension value to the new
value.
The length attribute must return the total
number of DOMRect objects associated with the object.
The item(index) method, when invoked, must
return null when index is greater than or equal to the number of DOMRect objects
associated with the DOMRectList. Otherwise, the DOMRect object at index must be
returned. Indices are zero-based.
DOMRectList only exists for compatibility with legacy Web content. When specifying a
new API, DOMRectList must not be used. Use sequence<DOMRect> instead. [WEBIDL]
The following algorithms assume that DOMQuad objects have the internal member variables point 1, point 2, point
3, and point 4, which are
DOMPoint objects. DOMQuad must be able to access and set the value of these variables. The
author can modify these DOMPoint objects, which directly affects the quadrilateral.
An interface returning a DOMQuad object by an attribute or function may be able to modify
internal member variable values. Such an interface must specify this ability explicitly in prose.
Internal member variables must not be exposed in any way.
The DOMQuad(p1, p2,
p3, p4) constructor, when invoked, must run the following steps:
Let point1 be a new DOMPoint object with its attributes set to the values of
the namesake dictionary members in p1.
Let point2 be a new DOMPoint object with its attributes set to the values of
the namesake dictionary members in p2.
Let point3 be a new DOMPoint object with its attributes set to the values of
the namesake dictionary members in p3.
Let point4 be a new DOMPoint object with its attributes set to the values of
the namesake dictionary members in p4.
Note: It is possible to pass DOMPoint/DOMPointReadOnly arguments as well. The passed
arguments will be transformed to the correct object type internally following the WebIDL rules.
[WEBIDL]
In this example the DOMQuad constructor is called with arguments of type DOMPoint and
DOMPointInit. Both arguments are accepted and can be used.
var point =new DOMPoint(2,0);var quad1 =new DOMQuad(point,{x:12, y:0},{x:12, y:10},{x:2, y:10});
The attribute values of the resulting DOMQuadquad1 above are also
equivalent to the attribute values of the following DOMQuadquad2:
var rect =new DOMRect(2,0,10,10);var quad2 = DOMQuad.fromRect(rect);
This is an example of an irregular quadrilateral:
new DOMQuad({x:40, y:25},{x:180, y:8},{x:210, y:150},{x:10, y:180});
An irregular quadrilateral represented by a DOMQuad. The four red colored
circles represent the DOMPoint attributes p1 to p4. The dashed
rectangle represents the bounding rectangle returned by the getBounds() method of the
DOMQuad.
6. The DOMMatrix interfaces
The DOMMatrix and DOMMatrixReadOnly interfaces each represent a mathematical matrix with the purpose of describing transformations in a graphical
context. The following sections describe the details of the interface.
A 4x4 abstract matrix with items m11 to m44.
In the following sections, terms have the following meaning:
post-multiply
Term A post-multiplied by term B is equal to A ·
B.
pre-multiply
Term A pre-multiplied by term B is equal to B ·
A.
The following algorithms assume that DOMMatrixReadOnly objects have the internal member
variables m11 element, m12 element, m13 element, m14 element, m21
element, m22 element, m23 element, m24 element, m31 element, m32
element, m33 element, m34 element, m41 element, m42 element, m43
element, m44 element and is 2D.
DOMMatrixReadOnly as well as the inheriting interface DOMMatrix must be able to access and
set the value of these variables.
An interface returning an DOMMatrixReadOnly object by an attribute or function may be able to
modify internal member variable values. Such an interface must specify this ability explicitly in
prose.
Internal member variables must not be exposed in any way.
If is2D is true and: at least one of m13,
m14, m23, m24, m31,
m32, m34, m43 are present with a value other
than 0 or -0, or at least one of m33, m44 are present
with a value other than 1, then throw a TypeError exception and abort these steps.
If is2D is not present and at least one of m13,
m14, m23, m24, m31,
m32, m34, m43 are present with a value other
than 0 or -0, or at least one of m33, m44 are present
with a value other than 1, set is2D to false.
To parse a string into an abstract matrix, given a string transformList,
means to run the following steps. It will either return a 4x4 abstract matrix and a boolean
2dTransform, or failure.
If transformList is the empty string, set it to the string "matrix(1, 0, 0,
1, 0, 0)".
Let matrix be a 4x4 abstract matrix as shown in the initial
figure of this section. Post-multiply all matrices from left to right and set
matrix to this product.
Return matrix and 2dTransform.
6.3. Creating DOMMatrixReadOnly and DOMMatrix objects
To create a 2d matrix of type type being either DOMMatrixReadOnly or
DOMMatrix, with a sequence init of 6 elements, follow these steps:
Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or
DOMMatrix as appropriate, with a sequence of numbers, the values being the elements m11, m12, m21, m22, m41 and m42 of matrix.
The fromFloat32Array(array32)
static method on DOMMatrixReadOnly and the fromFloat32Array(array32) static
method on DOMMatrix must follow these steps:
If array32 has 6 elements
Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or
DOMMatrix as appropriate, with a sequence of numbers taking the values from array32
in the provided order.
If array32 has 16 elements
Return the result of invoking create a 3d matrix of type DOMMatrixReadOnly or
DOMMatrix as appropriate, with a sequence of numbers taking the values from array32
in the provided order.
The fromFloat64Array(array64)
static method on DOMMatrixReadOnly and the fromFloat64Array(array64) static
method on DOMMatrix must follow these steps:
If array64 has 6 elements
Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or
DOMMatrix as appropriate, with a sequence of numbers taking the values from array64
in the provided order.
If array32 has 16 elements
Return the result of invoking create a 3d matrix of type DOMMatrixReadOnly or
DOMMatrix as appropriate, with a sequence of numbers taking the values from array64
in the provided order.
The following attributes m11 to m44 correspond to the
16 items of the matrix interfaces.
The m11 and a attributes, on getting, must
return the m11 element value. For the DOMMatrix interface, setting the
m11 or the a attribute must set the m11 element to
the new value.
The m12 and b attributes, on getting, must
return the m12 element value. For the DOMMatrix interface, setting the
m12 or the b attribute must set the m12 element to
the new value.
The m13 attribute, on getting, must return the m13
element value. For the DOMMatrix interface, setting the m13 attribute must
set the m13 element to the new value and, if the new value is not 0 or
-0, set is 2D to false.
The m14 attribute, on getting, must return the m14
element value. For the DOMMatrix interface, setting the m14 attribute must
set the m14 element to the new value and, if the new value is not 0 or
-0, set is 2D to false.
The m21 and c attributes, on getting, must
return the m21 element value. For the DOMMatrix interface, setting the
m21 or the c attribute must set the m21 element to
the new value.
The m22 and d attributes, on getting, must
return the m22 element value. For the DOMMatrix interface, setting the
m22 or the d attribute must set the m22 element to
the new value.
The m23 attribute, on getting, must return the m23
element value. For the DOMMatrix interface, setting the m23 attribute must
set the m23 element to the new value and, if the new value is not 0 or
-0, set is 2D to false.
The m24 attribute, on getting, must return the m24
element value. For the DOMMatrix interface, setting the m24 attribute must
set the m24 element to the new value and, if the new value is not 0 or
-0, set is 2D to false.
The m31 attribute, on getting, must return the m31
element value. For the DOMMatrix interface, setting the m31 attribute must
set the m31 element to the new value and, if the new value is not 0 or
-0, set is 2D to false.
The m32 attribute, on getting, must return the m32
element value. For the DOMMatrix interface, setting the m32 attribute must
set the m32 element to the new value and, if the new value is not 0 or
-0, set is 2D to false.
The m33 attribute, on getting, must return the m33
element value. For the DOMMatrix interface, setting the m33 attribute must
set the m33 element to the new value and, if the new value is not 1, set is 2D to false.
The m34 attribute, on getting, must return the m34
element value. For the DOMMatrix interface, setting the m34 attribute must
set the m34 element to the new value and, if the new value is not 0 or
-0, set is 2D to false.
The m41 and e attributes, on getting, must
return the m41 element value. For the DOMMatrix interface, setting the
m41 or the e attribute must set the m41 element to
the new value.
The m42 and f attributes, on getting, must
return the m42 element value. For the DOMMatrix interface, setting the
m42 or the f attribute must set the m42 element to
the new value.
The m43 attribute, on getting, must return the m43
element value. For the DOMMatrix interface, setting the m43 attribute must
set the m43 element to the new value and, if the new value is not 0 or
-0, set is 2D to false.
The m44 attribute, on getting, must return the m44
element value. For the DOMMatrix interface, setting the m44 attribute must
set the m44 element to the new value and, if the new value is not 1, set is 2D to false.
The following attributes a to f correspond to the 2D
components of the matrix interfaces.
For 3D operations, the stringifier returns a string representing a 3D matrix.
This example will throw an exception because there are non-finite values in the matrix.
var matrix =new DOMMatrix([NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN]);var string = matrix +" Batman!";
6.6. Mutable transformation methods
The following methods modify the current matrix, so that each method returns the matrix where it
was invoked on. The primary benefit of this is allowing content creators to chain method calls.
The following code example:
var matrix =new DOMMatrix();
matrix.translateSelf(20,20);
matrix.scaleSelf(2);
matrix.translateSelf(-20,-20);
is equivalent to:
var matrix =new DOMMatrix();
matrix.translateSelf(20,20).scaleSelf(2).translateSelf(-20,-20);
Note: Authors who use chained method calls are advised to use mutable transformation methods
to avoid unnecessary memory allocations due to creation of intermediate DOMMatrix objects in
user agents.
Perform a translateSelf() transformation on the current matrix with the
arguments originX, originY, originZ.
If scaleY is missing, set scaleY to the value of scaleX.
Post-multiply a non-uniform scale transformation on the current matrix. The 3D
scale matrix is described
in CSS Transforms with sx = scaleX, sy = scaleY and
sz = scaleZ. [CSS3-TRANSFORMS]
Negate originX, originY and originZ.
Perform a translateSelf() transformation on the current matrix with the
arguments originX, originY, originZ.
If scaleZ is not 1, set is 2D of the current matrix to false.
Return the current matrix.
scale3dSelf(scale, originX, originY,
originZ)
Apply a translateSelf() transformation to the current matrix with the
arguments originX, originY, originZ.
Post-multiply a uniform 3D scale transformation (m11 =
m22 = m33 = scale) on the current matrix.
The 3D scale matrix is described in CSS Transforms
with sx = sy = sz = scale. [CSS3-TRANSFORMS]
Apply a translateSelf() transformation to the current matrix with the
arguments -originX, -originY, -originZ.
If scale is not 1, set is 2D of the current matrix to
false.
Return the current matrix.
rotateSelf(rotX, rotY, rotZ)
If rotY and rotZ are both missing, set rotZ to the value
of rotX and set rotX and rotY to 0.
If rotY is still missing, set rotY to 0.
If rotZ is still missing, set rotZ to 0.
If rotX or rotY are not 0 or -0, set is 2D
of the current matrix to false.
Post-multiply a rotation transformation on the current matrix around the vector 0,
0, 1 by the specified rotation rotZ in degrees. The 3D rotation matrix is described in CSS Transforms
with alpha = rotZ in degrees. [CSS3-TRANSFORMS]
Post-multiply a rotation transformation on the current matrix around the vector 0,
1, 0 by the specified rotation rotY in degrees. The 3D rotation matrix is described in CSS Transforms
with alpha = rotY in degrees. [CSS3-TRANSFORMS]
Post-multiply a rotation transformation on the current matrix around the vector 1,
0, 0 by the specified rotation rotX in degrees. The 3D rotation matrix is described in CSS Transforms
with alpha = rotX in degrees. [CSS3-TRANSFORMS]
Return the current matrix.
rotateFromVectorSelf(x, y)
Post-multiply a rotation transformation on the current matrix. The rotation angle
is determined by the angle between the vector (1,0)T and
(x,y)T in the clockwise direction. If x and
y should both be 0 or -0, the angle is specified as 0. The 2D rotation
matrix is described in CSS
Transforms where alpha is the angle between the vector (1,0)T and
(x,y)T in degrees. [CSS3-TRANSFORMS]
Return the current matrix.
rotateAxisAngleSelf(x, y, z, angle)
Post-multiply a rotation transformation on the current matrix around the specified
vector x, y, z by the specified rotation angle in
degrees. The 3D rotation matrix is described in CSS Transforms
with alpha = angle in degrees. [CSS3-TRANSFORMS]
If x or y are not 0 or -0, set is 2D of
the current matrix to false.
Return the current matrix.
skewXSelf(sx)
Post-multiply a skewX transformation on the current matrix by the specified angle
sx in degrees. The 2D skewX matrix is described in CSS Transforms
with alpha = sx in degrees. [CSS3-TRANSFORMS]
Return the current matrix.
skewYSelf(sy)
Post-multiply a skewX transformation on the current matrix by the specified angle
sy in degrees. The 2D skewY matrix is described in CSS Transforms
with beta = sy in degrees. [CSS3-TRANSFORMS]
Return the current matrix.
invertSelf()
Invert the current matrix.
If the current matrix is not invertible set all attributes to NaN and set is 2D to false.
Note: It is possible for a 2D DOMMatrix or DOMMatrixReadOnly to have -0 for
some of the other elements, e.g., the m13 element, which will not be
roundtripped by this algorithm.
This could potentially be used to exploit bugs in the CSS parser in a user agent.
There are no other known security or privacy impacts of the interfaces defined in this
specification. However, other specifications that have APIs that use the interfaces defined in this
specification could potentially introduce security or privacy issues.
9. Privacy Considerations
For example, the getBoundingClientRect() API defined in CSSOM View returns a
DOMRect that could be used to measure the size of an inline element containing some text of a
particular font, which exposes information about whether the user has that font installed. That
information, if used to test many common fonts, can then be personally-identifiable information.
[CSSOM-VIEW]
10. Historical
This section is non-normative.
The interfaces in this specification are intended to replace earlier similar interfaces found in
various specifications as well as proprietary interfaces found in some user agents. This section
attempts to enumerate these interfaces.
10.1. CSSOM View
Earlier revisions of CSSOM View defined a ClientRect interface, which is replaced by
DOMRect. Implementations conforming to this specification will not support
ClientRect. [CSSOM-VIEW]
Some user agents supported a WebKitPoint interface. Implementations conforming to
this specification will not support WebKitPoint.
Several user agents supported a WebKitCSSMatrix interface, which is also widely used on the
Web. It is defined in this specification as an alias to DOMMatrix.
Some user agents supported a MSCSSMatrix interface. Implementations conforming to
this specification will not support MSCSSMatrix.
The NaN-safe minimum of a non-empty list of unrestricted double values is NaN if any
member of the list is NaN, or the minimum of the list otherwise.
Analogously, the NaN-safe maximum of a non-empty list of unrestricted double values
is NaN if any member of the list is NaN, or the maximum of the list otherwise.
Changed the interfaces to generally use specific static operations for construction instead
of using overloaded constructors, and made the interfaces more consistent. However, DOMMatrix
still uses an overloaded constructor for compatibility with WebKitCSSMatrix.
Changed rotate() and rotateSelf() arguments from
(angle, originX, originY) to (rotX, rotY, rotZ).
Changed the scale() and scaleSelf() methods to be more
like the previous scaleNonUniform()/scaleNonUniformSelf() methods,
and dropped the scaleNonUniformSelf() method. Keep support for scaleNonUniform()
for legacy reasons.
The editors would like to thank Robert O’Callahan for contributing to this specification.
Many thanks to Dean Jackson for his initial proposal of DOMMatrix.
Thanks to
Adenilson Cavalcanti,
Benoit Jacob,
Boris Zbarsky,
Brian Birtles,
Cameron McCormack,
Domenic Denicola,
Kari Pihkala,
Max Vujovic,
Mike Taylor,
Peter Hall,
Philip Jägenstedt,
Simon Fraser,
and
Timothy Loh
for their careful reviews, comments, and corrections.
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.