/
Overview.bs
2163 lines (1601 loc) · 93 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<h1>Geometry Interfaces Module Level 1</h1>
<!-- To the extent possible under law, the editors have waived all copyright and related or neighboring rights to this work. -->
<pre class=metadata>
Shortname: geometry
Level: 1
Status: ED
ED: https://drafts.fxtf.org/geometry/
TR: https://www.w3.org/TR/geometry-1/
Previous Version: https://www.w3.org/TR/2014/CR-geometry-1-20141125/
Previous Version: https://www.w3.org/TR/2014/WD-geometry-1-20140918/
Previous Version: https://www.w3.org/TR/2014/WD-geometry-1-20140626/
Previous Version: https://www.w3.org/TR/2014/WD-geometry-1-20140522/
Previous Version: https://www.w3.org/TR/2013/WD-matrix-20130919/
Group: fxtf
Ignored Terms: float32array, float64array, indexsizeerror, DOMString, boolean
Link Defaults: css-transforms-1 (type) <transform-list>/<transform-function>, css-transforms-1 (function) matrix3d()/matrix()
Editor: Simon Pieters, Opera Software AS, simonp@opera.com
Editor: Dirk Schulze, Adobe Systems Inc., dschulze@adobe.com
Editor: Rik Cabanier, Adobe Systems Inc., cabanier@adobe.com
Abstract: This specification provides basic geometric interfaces to represent points, rectangles, quadrilaterals and transformation matrices that can be used by other modules or specifications.
Issue Tracking: Legacy open bugs https://www.w3.org/Bugs/Public/buglist.cgi?product=FXTF&component=Geometry&resolution=---
Test Suite: http://test.csswg.org/suites/geometry-1_dev/nightly-unstable/
Use <i> Autolinks: no
Include Can I Use Panels: true
Can I Use URL: https://drafts.fxtf.org/geometry/
Can I Use URL: https://www.w3.org/TR/geometry-1/
Ignore Can I Use URL Failure: https://drafts.fxtf.org/geometry/
Ignore Can I Use URL Failure: https://www.w3.org/TR/geometry-1/
Complain About: accidental-2119 true
Default Highlight: javascript
</pre>
<pre class=anchors>
type: exception; text: SyntaxError; url: https://html.spec.whatwg.org/multipage/infrastructure.html#js-syntaxerror
urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
type: dfn
text: ToString; url: sec-tostring
text: !; url: sec-algorithm-conventions
</pre>
<script src=https://resources.whatwg.org/file-issue.js async data-file-issue-url="https://github.com/w3c/fxtf-drafts/issues/new?title=[geometry]%20"></script>
<script src="../shared/MathJax/MathJax.js?config=MML_SVGorMML,local/local"></script>
<style>
a.selected-text-file-an-issue {
position: fixed;
bottom: 0;
right: 0;
background: rgba(255, 255, 255, 0.8);
font-size: smaller;
padding: 4px 10px;
z-index: 4;
}
</style>
<h2 id=intro>Introduction</h2>
<p>This specification describes several geometry interfaces for the representation of points,
rectangles, quadrilaterals and transformation matrices with the dimension of 3x2 and 4x4.
<p>The SVG interfaces {{SVGPoint}}, {{SVGRect}} and {{SVGMatrix}} are aliasing the here defined
interfaces in favor for common interfaces used by SVG, Canvas 2D Context and CSS
Transforms. [[SVG11]] [[2DCONTEXT]] [[CSS3-TRANSFORMS]]
<h2 id=DOMPoint>The DOMPoint interfaces</h2>
<p>A 2D or a 3D <dfn>point</dfn> can be represented by the following WebIDL interfaces:
<pre class=idl>
[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double z = 0, optional unrestricted double w = 1),
Exposed=(Window,Worker),
Serializable]
interface DOMPointReadOnly {
[NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other);
readonly attribute unrestricted double x;
readonly attribute unrestricted double y;
readonly attribute unrestricted double z;
readonly attribute unrestricted double w;
DOMPoint matrixTransform(optional DOMMatrixInit matrix);
serializer = { attribute };
};
[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double z = 0, optional unrestricted double w = 1),
Exposed=(Window,Worker),
Serializable]
interface DOMPoint : DOMPointReadOnly {
[NewObject] static DOMPoint fromPoint(optional DOMPointInit other);
inherit attribute unrestricted double x;
inherit attribute unrestricted double y;
inherit attribute unrestricted double z;
inherit attribute unrestricted double w;
};
dictionary DOMPointInit {
unrestricted double x = 0;
unrestricted double y = 0;
unrestricted double z = 0;
unrestricted double w = 1;
};
</pre>
<p>The following algorithms assume that {{DOMPointReadOnly}} objects have the internal member
variables <dfn dfn-for=point id=point-x-coordinate>x coordinate</dfn>, <dfn dfn-for=point
id=point-y-coordinate>y coordinate</dfn>, <dfn dfn-for=point id=point-z-coordinate>z
coordinate</dfn> and <dfn dfn-for=point id=point-w-perspective>w perspective</dfn>.
{{DOMPointReadOnly}} as well as the inheriting interface {{DOMPoint}} must be able to access and set
the value of these variables.
<p>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.
<p>Internal member variables must not be exposed in any way.
<p>The <dfn dfn-type=constructor dfn-for=DOMPointReadOnly><code>DOMPointReadOnly(<var>x</var>,
<var>y</var>, <var>z</var>, <var>w</var>)</code></dfn> and <dfn dfn-type=constructor
dfn-for=DOMPoint><code>DOMPoint(<var>x</var>, <var>y</var>, <var>z</var>, <var>w</var>)</code></dfn>
constructors, when invoked, must run the following steps:
<ol>
<li><p>Let <var>point</var> be a new {{DOMPointReadOnly}} or {{DOMPoint}} object as appropriate.
<li><p>Set <var>point</var>'s variables <a for=point>x coordinate</a> to <var>x</var>, <a
for=point>y coordinate</a> to <var>y</var>, <a for=point>z coordinate</a> to <var>z</var> and <a
for=point>w perspective</a> to <var>w</var>.
<li><p>Return <var>point</var>.
</ol>
<p>The <dfn method dfn-for=DOMPointReadOnly
id=dom-dompointreadonly-frompoint><code>fromPoint(<var>other</var>)</code></dfn> static method on
{{DOMPointReadOnly}} must <a>create a <code>DOMPointReadOnly</code> from the dictionary</a>
<var>other</var>.
<p>The <dfn method dfn-for=DOMPoint
id=dom-dompoint-frompoint><code>fromPoint(<var>other</var>)</code></dfn> static method on
{{DOMPoint}} <a>create a <code>DOMPoint</code> from the dictionary</a> <var>other</var>.
<p>To <dfn lt="create a DOMPointReadOnly from the dictionary">create a <code>DOMPointReadOnly</code>
from a dictionary</dfn> <var>other</var>, or to <dfn lt="create a DOMPoint from the
dictionary">create a <code>DOMPoint</code> from a dictionary</dfn> <var>other</var>, follow these
steps:
<ol>
<li><p>Let <var>point</var> be a new {{DOMPointReadOnly}} or {{DOMPoint}} as appropriate.
<li><p>Set <var>point</var>'s variables <a for=point>x coordinate</a> to <var>other</var>'s
{{DOMPointInit/x}} dictionary member, <a for=point>y coordinate</a> to <var>other</var>'s
{{DOMPointInit/y}} dictionary member, <a for=point>z coordinate</a> to <var>other</var>'s
{{DOMPointInit/z}} dictionary member and <a for=point>w perspective</a> to <var>other</var>'s
{{DOMPointInit/w}} dictionary member.
<li><p>Return <var>point</var>.
</ol>
<div dfn-type=attribute dfn-for="DOMPointReadOnly, DOMPoint">
<p>The <dfn><code>x</code></dfn> attribute, on getting, must return the <a for=point>x
coordinate</a> value. For the {{DOMPoint}} interface, setting the
{{DOMPoint/x}} attribute must set the <a for=point>x coordinate</a> to the new value.
<p>The <dfn><code>y</code></dfn> attribute, on getting, must return the <a for=point>y
coordinate</a> value. For the {{DOMPoint}} interface, setting the
{{DOMPoint/y}} attribute must set the <a for=point>y coordinate</a> to the new value.
<p>The <dfn><code>z</code></dfn> attribute, on getting, must return the <a for=point>z
coordinate</a> value. For the {{DOMPoint}} interface, setting the
{{DOMPoint/z}} attribute must set the <a for=point>z coordinate</a> to the new value.
<p>The <dfn><code>w</code></dfn> attribute, on getting, must return the <a for=point>w
perspective</a> value. For the {{DOMPoint}} interface, setting the
{{DOMPoint/w}} attribute must set the <a for=point>w perspective</a> to the new value.
</div>
<p>The <dfn dfn-type=method dfn-for=DOMPointReadOnly>matrixTransform(<var>matrix</var>)</dfn>
method, when invoked, must run the following steps:
<ol>
<li><p>Create a new {{DOMPoint}} <var>point</var> initialized to {{DOMPoint/x}}, {{DOMPoint/y}},
{{DOMPoint/z}} and {{DOMPoint/w}} of the current point.
<li><p>Let <var>matrixObject</var> be the result of invoking <a>create a <code>DOMMatrix</code>
from the dictionary</a> <var>matrix</var>.
<li><a for=matrix>Post-multiply</a> <var>point</var> with <var>matrixObject</var>.
<li><p>Return <var>point</var>.
</ol>
<p>{{DOMPointReadOnly/matrixTransform()}} does not modify the current {{DOMPointReadOnly}} object
and returns a new {{DOMPoint}} object.
<div class=example>
<p>In this example the method {{DOMPointReadOnly/matrixTransform()}} on <var ignore>point</var> is
called with a {{DOMMatrix}} argument <var ignore>matrix</var>.
<pre><code>
var point = new DOMPoint(5, 4);
var matrix = new DOMMatrix([2, 0, 0, 2, 10, 10]);
var transformedPoint = point.matrixTransform(matrix);
</code></pre>
<p><var ignore>point</var> creates a new {{DOMPoint}} object initialized to the same
attribute values as <var ignore>point</var>. This new {{DOMPoint}} is now scaled and
the translated by <var ignore>matrix</var>. This resulting <var ignore>transformPoint</var> has
the attribute values <code>x: 20</code> and <code>y: 18</code>.
</div>
<p>For historical reasons, {{Window}} objects must also have a writable, configurable,
non-enumerable property named <dfn dfn-type=interface><code>SVGPoint</code></dfn> whose value is the
{{DOMPoint}} interface object.
<h2 id=DOMRect>The DOMRect interfaces</h2>
<p>Objects implementing the {{DOMRectReadOnly}} interface represent a <dfn>rectangle</dfn>. The type
of box is specified by the method or attribute that returns a {{DOMRect}} or {{DOMRectReadOnly}}
object.
<p><a>Rectangles</a> have the following properties:
<dl dfn-for=rectangle>
<dt><dfn for=rectangle id=rectangle-origin>origin</dfn>
<dd><p>When the rectangle has a non-negative <a for=rectangle>width dimension</a>, the rectangle's
horizontal origin is the left edge; otherwise, it is the right edge. Similarly, when the rectangle
has a non-negative <a for=rectangle>height dimension</a>, the rectangle's vertical origin is the
top edge; otherwise, it is the bottom edge.
<dt><dfn for=rectangle id=rectangle-x-coordinate>x coordinate</dfn>
<dd><p>The horizontal distance between the viewport's left edge and the rectangle's <a
for=rectangle>origin</a>.
<dt><dfn for=rectangle id=rectangle-y-coordinate>y coordinate</dfn>
<dd><p>The vertical distance between the viewport's top edge and the rectangle's <a
for=rectangle>origin</a>.
<dt><dfn for=rectangle id=rectangle-width-dimension>width dimension</dfn>
<dd><p>The width of the rectangle. Can be negative.
<dt><dfn for=rectangle id=rectangle-height-dimension>height dimension</dfn>
<dd><p>The height of the rectangle. Can be negative.
</dl>
<pre class=idl>
[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double width = 0, optional unrestricted double height = 0),
Exposed=(Window,Worker),
Serializable]
interface DOMRectReadOnly {
[NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other);
readonly attribute unrestricted double x;
readonly attribute unrestricted double y;
readonly attribute unrestricted double width;
readonly attribute unrestricted double height;
readonly attribute unrestricted double top;
readonly attribute unrestricted double right;
readonly attribute unrestricted double bottom;
readonly attribute unrestricted double left;
serializer = { attribute };
};
[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double width = 0, optional unrestricted double height = 0),
Exposed=(Window,Worker),
Serializable]
interface DOMRect : DOMRectReadOnly {
[NewObject] static DOMRect fromRect(optional DOMRectInit other);
inherit attribute unrestricted double x;
inherit attribute unrestricted double y;
inherit attribute unrestricted double width;
inherit attribute unrestricted double height;
};
dictionary DOMRectInit {
unrestricted double x = 0;
unrestricted double y = 0;
unrestricted double width = 0;
unrestricted double height = 0;
};
</pre>
<p>The following algorithms assume that {{DOMRectReadOnly}} objects have the internal member
variables <a for=rectangle>x coordinate</a>, <a for=rectangle>y coordinate</a>, <a
for=rectangle>width dimension</a> and <a for=rectangle>height dimension</a>. {{DOMRectReadOnly}} as
well as the inheriting interface {{DOMRect}} must be able to access and set the value of these
variables.
<p>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.
<p>Internal member variables must not be exposed in any way.
<p>The <dfn dfn-type=constructor dfn-for=DOMRectReadOnly><code>DOMRectReadOnly(<var>x</var>,
<var>y</var>, <var>width</var>, <var>height</var>)</code></dfn> and <dfn dfn-type=constructor
dfn-for=DOMRect><code>DOMRect(<var>x</var>, <var>y</var>, <var>width</var>,
<var>height</var>)</code></dfn> constructors, when invoked, must run the following steps:
<ol>
<li><p>Let <var>rect</var> be a new {{DOMRectReadOnly}} or {{DOMRect}} object as appropriate.
<li><p>Set <var>rect</var>'s variables <a for=rectangle>x coordinate</a> to <var>x</var>, <a
for=rectangle>y coordinate</a> to <var>y</var>, <a for=rectangle>width dimension</a> to
<var>width</var> and <a for=rectangle>height dimension</a> to <var>height</var>.
<li><p>Return <var>rect</var>.
</ol>
<p>The <dfn method lt=fromRect() dfn-for=DOMRectReadOnly
id=dom-domrectreadonly-fromrect><code>fromRect(<var>other</var>)</code></dfn> static method on
{{DOMRectReadOnly}} must <a>create a <code>DOMRectReadOnly</code> from the dictionary</a>
<var>other</var>.
<p>The <dfn method lt=fromRect() dfn-for=DOMRect
id=dom-domrect-fromrect><code>fromRect(<var>other</var>)</code></dfn> static method on {{DOMRect}}
must <a>create a <code>DOMRect</code> from the dictionary</a> <var>other</var>.
<p>To <dfn lt="create a DOMRectReadOnly from the dictionary">create a <code>DOMRectReadOnly</code>
from a dictionary</dfn> <var>other</var>, or to <dfn lt="create a DOMRect from the
dictionary">create a <code>DOMRect</code> from a dictionary</dfn> <var>other</var>, follow these
steps:
<ol>
<li><p>Let <var>rect</var> be a new {{DOMRectReadOnly}} or {{DOMRect}} as appropriate.
<li><p>Set <var>rect</var>'s variables <a for=rectangle>x coordinate</a> to <var>other</var>'s
{{DOMRectInit/x}} dictionary member, <a for=rectangle>y coordinate</a> to <var>other</var>'s
{{DOMRectInit/y}} dictionary member, <a for=rectangle>width dimension</a> to <var>other</var>'s
{{DOMRectInit/width}} dictionary member and <a for=rectangle>height dimension</a> to
<var>other</var>'s {{DOMRectInit/height}} dictionary member.
<li><p>Return <var>rect</var>.
</ol>
<div dfn-type=attribute dfn-for="DOMRectReadOnly DOMRect">
<p>The <dfn><code>x</code></dfn> attribute, on getting, must return the <a for=rectangle>x
coordinate</a> value. For the {{DOMRect}} interface, setting the
{{DOMRect/x}} attribute must set the <a for=rectangle>x coordinate</a> to the new value.
<p>The <dfn><code>y</code></dfn> attribute, on getting, it must return the <a for=rectangle>y
coordinate</a> value. For the {{DOMRect}} interface, setting the
{{DOMRect/y}} attribute must set the <a for=rectangle>y coordinate</a> to the new value.
<p>The <dfn><code>width</code></dfn> attribute, on getting, must return the <a for=rectangle>width
dimension</a> value. For the {{DOMRect}} interface, setting the
{{DOMRect/width}} attribute must set the <a for=rectangle>width dimension</a> to the new value.
<p>The <dfn><code>height</code></dfn> attribute, on getting, must return the <a
for=rectangle>height dimension</a> value. For the {{DOMRect}} interface, setting the
{{DOMRect/height}} attribute must set the <a for=rectangle>height dimension</a> value to the new
value.
<p>The <dfn><code>top</code></dfn> attribute, on getting, must return min(<a for=rectangle>y
coordinate</a>, <a for=rectangle>y coordinate</a> + <a for=rectangle>height dimension</a>).
<p>The <dfn><code>right</code></dfn> attribute, on getting, must return max(<a for=rectangle>x
coordinate</a>, <a for=rectangle>x coordinate</a> + <a for=rectangle>width dimension</a>).
<p>The <dfn><code>bottom</code></dfn> attribute, on getting, must return max(<a for=rectangle>y
coordinate</a>, <a for=rectangle>y coordinate</a> + <a for=rectangle>height dimension</a>).
<p>The <dfn><code>left</code></dfn> attribute, on getting, must return min(<a for=rectangle>x
coordinate</a>, <a for=rectangle>x coordinate</a> + <a for=rectangle>width dimension</a>).
</div>
<p>For historical reasons, {{Window}} objects must also have a writable, configurable,
non-enumerable property named <dfn dfn-type=interface><code>SVGRect</code></dfn> whose value is the
{{DOMRect}} interface object.
<h2 id=DOMQuad>The DOMQuad interface</h2>
<p>Objects implementing the {{DOMQuad}} interface represents a <dfn>quadrilateral</dfn>.
<pre class=idl>
[Constructor(optional DOMPointInit p1, optional DOMPointInit p2,
optional DOMPointInit p3, optional DOMPointInit p4),
Exposed=(Window,Worker),
Serializable]
interface DOMQuad {
[NewObject] static DOMQuad fromRect(optional DOMRectInit other);
[NewObject] static DOMQuad fromQuad(optional DOMQuadInit other);
[SameObject] readonly attribute DOMPoint p1;
[SameObject] readonly attribute DOMPoint p2;
[SameObject] readonly attribute DOMPoint p3;
[SameObject] readonly attribute DOMPoint p4;
[NewObject] DOMRect getBounds();
serializer = { attribute };
};
dictionary DOMQuadInit {
DOMPointInit p1;
DOMPointInit p2;
DOMPointInit p3;
DOMPointInit p4;
};
</pre>
<p>The following algorithms assume that {{DOMQuad}} objects have the internal member variables <dfn
dfn-for=quadrilateral id=quadrilateral-point-1>point 1</dfn>, <dfn dfn-for=quadrilateral
id=quadrilateral-point-2>point 2</dfn>, <dfn dfn-for=quadrilateral id=quadrilateral-point-3>point
3</dfn>, and <dfn dfn-for=quadrilateral id=quadrilateral-point-4>point 4</dfn>, 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.
<p>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.
<p>Internal member variables must not be exposed in any way.
<p>The <dfn dfn-type=constructor dfn-for=DOMQuad><code>DOMQuad(<var>p1</var>, <var>p2</var>,
<var>p3</var>, <var>p4</var>)</code></dfn> constructor, when invoked, must run the following steps:
<ol>
<li><p>Let <var>point1</var> be a new {{DOMPoint}} object with its attributes set to the values of
the namesake dictionary members in <var>p1</var>.
<li><p>Let <var>point2</var> be a new {{DOMPoint}} object with its attributes set to the values of
the namesake dictionary members in <var>p2</var>.
<li><p>Let <var>point3</var> be a new {{DOMPoint}} object with its attributes set to the values of
the namesake dictionary members in <var>p3</var>.
<li><p>Let <var>point4</var> be a new {{DOMPoint}} object with its attributes set to the values of
the namesake dictionary members in <var>p4</var>.
<li><p>Return a new {{DOMQuad}} with <a for=quadrilateral>point 1</a> set to <var>point1</var>, <a
for=quadrilateral>point 2</a> set to <var>point2</var>, <a for=quadrilateral>point 3</a> set to
<var>point3</var> and <a for=quadrilateral>point 4</a> set to <var>point4</var>.
</ol>
<p class=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]]
<p>The <dfn method lt=fromRect() dfn-for=DOMQuad><code>fromRect(<var>other</var>)</code></dfn>
static method on {{DOMQuad}} must <a>create a <code>DOMQuad</code> from the <code>DOMRectInit</code>
dictionary</a> <var>other</var>.
<p>To <dfn lt="create a DOMQuad from the DOMRectInit dictionary">create a <code>DOMQuad</code> from
a <code>DOMRectInit</code> dictionary</dfn> <var>other</var>, follow these steps:
<ol>
<li><p>Let <var>x</var>, <var>y</var>, <var>width</var> and <var>height</var> be the value of
<var>other</var>'s {{DOMRectInit/x}}, {{DOMRectInit/y}}, {{DOMRectInit/width}} and
{{DOMRectInit/height}} dictionary members, respectively.
<li><p>Let <var>point1</var> be a new {{DOMPoint}} object with <a for=point>x coordinate</a> set to
<var>x</var>, <a for=point>y coordinate</a> set to <var>y</var>, <a for=point>z coordinate</a> set
to zero and <a for=point>w perspective</a> set to one.
<li><p>Let <var>point2</var> be a new {{DOMPoint}} object with <a for=point>x coordinate</a> set to
<var>x</var> + <var>width</var>, <a for=point>y coordinate</a> set to <var>y</var>, <a for=point>z
coordinate</a> set to zero and <a for=point>w perspective</a> set to one.
<li><p>Let <var>point3</var> be a new {{DOMPoint}} object with <a for=point>x coordinate</a> set to
<var>x</var> + <var>width</var>, <a for=point>y coordinate</a> set to <var>y</var> +
<var>height</var>, <a for=point>z coordinate</a> set to zero and <a for=point>w perspective</a> set
to one.
<li><p>Let <var>point4</var> be a new {{DOMPoint}} object with <a for=point>x coordinate</a> set to
<var>x</var>, <a for=point>y coordinate</a> set to <var>y</var> + <var>height</var>, <a for=point>z
coordinate</a> set to zero and <a for=point>w perspective</a> set to one.
<li><p>Return a new {{DOMQuad}} with <a for=quadrilateral>point 1</a> set to <var>point1</var>, <a
for=quadrilateral>point 2</a> set to <var>point2</var>, <a for=quadrilateral>point 3</a> set to
<var>point3</var> and <a for=quadrilateral>point 4</a> set to <var>point4</var>.
</ol>
<p>The <dfn method lt=fromQuad() dfn-for=DOMQuad><code>fromQuad(<var>other</var>)</code></dfn>
static method on {{DOMQuad}} must <a>create a <code>DOMQuad</code> from the <code>DOMQuadInit</code>
dictionary</a> <var>other</var>.
<p>To <dfn lt="create a DOMQuad from the DOMQuadInit dictionary">create a <code>DOMQuad</code> from
a <code>DOMQuadInit</code> dictionary</dfn> <var>other</var>, follow these steps:
<ol>
<li><p>Let <var>point1</var> be the result of invoking <a>create a <code>DOMPoint</code> from the
dictionary</a> {{DOMQuadInit/p1}} dictionary member of <var>other</var>, if it exists.
<li><p>Let <var>point2</var> be the result of invoking <a>create a <code>DOMPoint</code> from the
dictionary</a> {{DOMQuadInit/p2}} dictionary member of <var>other</var>, if it exists.
<li><p>Let <var>point3</var> be the result of invoking <a>create a <code>DOMPoint</code> from the
dictionary</a> {{DOMQuadInit/p3}} dictionary member of <var>other</var>, if it exists.
<li><p>Let <var>point4</var> be the result of invoking <a>create a <code>DOMPoint</code> from the
dictionary</a> {{DOMQuadInit/p4}} dictionary member of <var>other</var>, if it exists.
<li><p>Return a new {{DOMQuad}} with <a for=quadrilateral>point 1</a> set to <var>point1</var>, <a
for=quadrilateral>point 2</a> set to <var>point2</var>, <a for=quadrilateral>point 3</a> set to
<var>point3</var> and <a for=quadrilateral>point 4</a> set to <var>point4</var>.
</ol>
<div dfn-type=attribute dfn-for=DOMQuad>
<p>The <dfn><code>p1</code></dfn> attribute must return <a for=quadrilateral>point 1</a>.
<p>The <dfn><code>p2</code></dfn> attribute must return <a for=quadrilateral>point 2</a>.
<p>The <dfn><code>p3</code></dfn> attribute must return <a for=quadrilateral>point 3</a>.
<p>The <dfn><code>p4</code></dfn> attribute must return <a for=quadrilateral>point 4</a>.
</div>
<p>The <dfn method for=DOMQuad>getBounds()</dfn> method, when invoked, must run the following
algorithm:
<ol>
<li><p>Let <var>bounds</var> be a {{DOMRect}} object.
<li><p>Let <var>left</var> be the minimum of <a for=quadrilateral>point 1</a>'s <a for=point>x
coordinate</a>, <a for=quadrilateral>point 2</a>'s <a for=point>x coordinate</a>, <a
for=quadrilateral>point 3</a>'s <a for=point>x coordinate</a> and <a for=quadrilateral>point
4</a>'s <a for=point>x coordinate</a>.
<li><p>Let <var>top</var> be the minimum of <a for=quadrilateral>point 1</a>'s <a for=point>y
coordinate</a>, <a for=quadrilateral>point 2</a>'s <a for=point>y coordinate</a>, <a
for=quadrilateral>point 3</a>'s <a for=point>y coordinate</a> and <a for=quadrilateral>point
4</a>'s <a for=point>y coordinate</a>.
<li><p>Let <var>right</var> be the maximum of <a for=quadrilateral>point 1</a>'s <a for=point>x
coordinate</a>, <a for=quadrilateral>point 2</a>'s <a for=point>x coordinate</a>, <a
for=quadrilateral>point 3</a>'s <a for=point>x coordinate</a> and <a for=quadrilateral>point
4</a>'s <a for=point>x coordinate</a>.
<li><p>Let <var>bottom</var> be the maximum of <a for=quadrilateral>point 1</a>'s <a for=point>y
coordinate</a>, <a for=quadrilateral>point 2</a>'s <a for=point>y coordinate</a>, <a
for=quadrilateral>point 3</a>'s <a for=point>y coordinate</a> and <a for=quadrilateral>point
4</a>'s <a for=point>y coordinate</a>.
<li><p>Set <a for=rectangle>x coordinate</a> of <var>bounds</var> to <var>left</var>, <a
for=rectangle>y coordinate</a> of <var>bounds</var> to <var>top</var>, <a for=rectangle>width
dimension</a> of <var>bounds</var> to <var>right</var> - <var>left</var> and <a
for=rectangle>height dimension</a> of <var>bounds</var> to <var>bottom</var> - <var>top</var>.
<li><p>Return <var>bounds</var>.
</ol>
<div class=example>
<p>In this example the {{DOMQuad}} constructor is called with arguments of type {{DOMPoint}} and
{{DOMPointInit}}. Both arguments are accepted and can be used.
<pre><code>
var point = new DOMPoint(2, 0);
var quad1 = new DOMQuad(point, {x: 12, y: 0}, {x: 2, y: 10}, {x: 12, y: 10});
</code></pre>
<p>The attribute values of the resulting {{DOMQuad}} <var ignore>quad1</var> above are also equal
to the attribute values of the following {{DOMQuad}} <var ignore>quad2</var>:
<pre><code>
var rect = new DOMRect(2, 0, 10, 10);
var quad2 = DOMQuad.fromRect(rect);
</code></pre>
</div>
<div class=example>
<p>This is an example of an irregular quadrilateral:
<pre><code>
new DOMQuad({x: 40, y: 25}, {x: 180, y: 8}, {x: 210, y: 150}, {x: 10, y: 180});
</code></pre>
<div class="figure">
<svg width="230" height="200">
<title>An irregular quadrilateral with none of the sides being vertical or horizontal. Its four
corners are marked with red circles. Around this quadrilateral is a dashed rectangle. All sides
of this rectangle are vertical or horizontal and tangent the quadrilateral.</title>
<polygon points="40 25, 180 8, 210 150, 10 180" fill="rgb(51, 153, 204)"/>
<rect x="10" y="8" width="200" height="172" fill="none" stroke="black" stroke-dasharray="3 2"/>
<circle cx="40" cy="25" r="3" fill="rgb(204, 51, 51)"/>
<circle cx="180" cy="8" r="3" fill="rgb(204, 51, 51)"/>
<circle cx="210" cy="150" r="3" fill="rgb(204, 51, 51)"/>
<circle cx="10" cy="180" r="3" fill="rgb(204, 51, 51)"/>
</svg>
<p class="capture">An irregular quadrilateral represented by a {{DOMQuad}}. The four red colored
circles represent the {{DOMPoint}} attributes {{DOMQuad/p1}} to {{DOMQuad/p4}}. The dashed
rectangle represents the bounding rectangle returned by the {{DOMQuad/getBounds()}} method of the
{{DOMQuad}}.
</div>
</div>
<h2 id=DOMMatrix>The DOMMatrix interfaces</h2>
<p>The {{DOMMatrix}} and {{DOMMatrixReadOnly}} interfaces each represent a mathematical <dfn
caniuse=dommatrix>matrix</dfn> with the purpose of describing transformations in a graphical
context. The following sections describe the details of the interface.
<div class="figure">
<!--<img src="images/4x4matrix.png" alt="4x4 matrix with items m11 to m44">-->
<math display=block><mrow><mfenced open=[ close=] separators=,><mrow><mtable><mtr><mtd><msub><mi>m</mi><mi>11</mi></msub></mtd><mtd><msub><mi>m</mi><mi>21</mi></msub></mtd><mtd><msub><mi>m</mi><mi>31</mi></msub></mtd><mtd><msub><mi>m</mi><mi>41</mi></msub></mtd></mtr><mtr><mtd><msub><mi>m</mi><mi>12</mi></msub></mtd><mtd><msub><mi>m</mi><mi>22</mi></msub></mtd><mtd><msub><mi>m</mi><mi>32</mi></msub></mtd><mtd><msub><mi>m</mi><mi>42</mi></msub></mtd></mtr><mtr><mtd><msub><mi>m</mi><mi>13</mi></msub></mtd><mtd><msub><mi>m</mi><mi>23</mi></msub></mtd><mtd><msub><mi>m</mi><mi>33</mi></msub></mtd><mtd><msub><mi>m</mi><mi>43</mi></msub></mtd></mtr><mtr><mtd><msub><mi>m</mi><mi>14</mi></msub></mtd><mtd><msub><mi>m</mi><mi>24</mi></msub></mtd><mtd><msub><mi>m</mi><mi>34</mi></msub></mtd><mtd><msub><mi>m</mi><mi>44</mi></msub></mtd></mtr></mtable></mrow></mfenced></mrow></math>
<p class="capture">A 4x4 matrix representing a {{DOMMatrix}} with items m11 to m44.
</div>
<p>In the following sections, terms have the following meaning:
<dl dfn-for=matrix>
<dt><dfn>post-multiply</dfn>
<dd><p>Term <var>A</var> post-multiplied by term <var>B</var> is equal to <var>A</var> ·
<var>B</var>.
<dt><dfn>pre-multiply</dfn>
<dd><p>Term <var>A</var> pre-multiplied by term <var>B</var> is equal to <var>B</var> ·
<var>A</var>.
<dt><dfn>multiply</dfn>
<dd><p>Multiply term <var>A</var> by term <var>B</var> is equal to <var>A</var> ·
<var>B</var>.
</dl>
<pre class=idl>
[Constructor(optional (DOMString or sequence<unrestricted double>) init),
Exposed=(Window,Worker),
Serializable]
interface DOMMatrixReadOnly {
[NewObject] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other);
[NewObject] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
[NewObject] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64);
// These attributes are simple aliases for certain elements of the 4x4 matrix
readonly attribute unrestricted double a;
readonly attribute unrestricted double b;
readonly attribute unrestricted double c;
readonly attribute unrestricted double d;
readonly attribute unrestricted double e;
readonly attribute unrestricted double f;
readonly attribute unrestricted double m11;
readonly attribute unrestricted double m12;
readonly attribute unrestricted double m13;
readonly attribute unrestricted double m14;
readonly attribute unrestricted double m21;
readonly attribute unrestricted double m22;
readonly attribute unrestricted double m23;
readonly attribute unrestricted double m24;
readonly attribute unrestricted double m31;
readonly attribute unrestricted double m32;
readonly attribute unrestricted double m33;
readonly attribute unrestricted double m34;
readonly attribute unrestricted double m41;
readonly attribute unrestricted double m42;
readonly attribute unrestricted double m43;
readonly attribute unrestricted double m44;
readonly attribute boolean is2D;
readonly attribute boolean isIdentity;
// Immutable transform methods
[NewObject] DOMMatrix translate(optional unrestricted double tx = 0,
optional unrestricted double ty = 0,
optional unrestricted double tz = 0);
[NewObject] DOMMatrix scale(optional unrestricted double scaleX = 1,
optional unrestricted double scaleY,
optional unrestricted double scaleZ = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
[NewObject] DOMMatrix scale3d(optional unrestricted double scale = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
[NewObject] DOMMatrix rotate(optional unrestricted double rotX = 0,
optional unrestricted double rotY,
optional unrestricted double rotZ);
[NewObject] DOMMatrix rotateFromVector(optional unrestricted double x = 0,
optional unrestricted double y = 0);
[NewObject] DOMMatrix rotateAxisAngle(optional unrestricted double x = 0,
optional unrestricted double y = 0,
optional unrestricted double z = 0,
optional unrestricted double angle = 0);
[NewObject] DOMMatrix skewX(optional unrestricted double sx = 0);
[NewObject] DOMMatrix skewY(optional unrestricted double sy = 0);
[NewObject] DOMMatrix multiply(optional DOMMatrixInit other);
[NewObject] DOMMatrix flipX();
[NewObject] DOMMatrix flipY();
[NewObject] DOMMatrix inverse();
[NewObject] DOMPoint transformPoint(optional DOMPointInit point);
[NewObject] Float32Array toFloat32Array();
[NewObject] Float64Array toFloat64Array();
[Exposed=Window] stringifier;
serializer = { attribute };
};
[Constructor(optional (DOMString or sequence<unrestricted double>) init),
Exposed=(Window,Worker),
Serializable]
interface DOMMatrix : DOMMatrixReadOnly {
[NewObject] static DOMMatrix fromMatrix(optional DOMMatrixInit other);
[NewObject] static DOMMatrix fromFloat32Array(Float32Array array32);
[NewObject] static DOMMatrix fromFloat64Array(Float64Array array64);
// These attributes are simple aliases for certain elements of the 4x4 matrix
inherit attribute unrestricted double a;
inherit attribute unrestricted double b;
inherit attribute unrestricted double c;
inherit attribute unrestricted double d;
inherit attribute unrestricted double e;
inherit attribute unrestricted double f;
inherit attribute unrestricted double m11;
inherit attribute unrestricted double m12;
inherit attribute unrestricted double m13;
inherit attribute unrestricted double m14;
inherit attribute unrestricted double m21;
inherit attribute unrestricted double m22;
inherit attribute unrestricted double m23;
inherit attribute unrestricted double m24;
inherit attribute unrestricted double m31;
inherit attribute unrestricted double m32;
inherit attribute unrestricted double m33;
inherit attribute unrestricted double m34;
inherit attribute unrestricted double m41;
inherit attribute unrestricted double m42;
inherit attribute unrestricted double m43;
inherit attribute unrestricted double m44;
// Mutable transform methods
DOMMatrix multiplySelf(optional DOMMatrixInit other);
DOMMatrix preMultiplySelf(optional DOMMatrixInit other);
DOMMatrix translateSelf(optional unrestricted double tx = 0,
optional unrestricted double ty = 0,
optional unrestricted double tz = 0);
DOMMatrix scaleSelf(optional unrestricted double scaleX = 1,
optional unrestricted double scaleY,
optional unrestricted double scaleZ = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix scale3dSelf(optional unrestricted double scale = 1,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix rotateSelf(optional unrestricted double rotX = 0,
optional unrestricted double rotY,
optional unrestricted double rotZ);
DOMMatrix rotateFromVectorSelf(optional unrestricted double x = 0,
optional unrestricted double y = 0);
DOMMatrix rotateAxisAngleSelf(optional unrestricted double x = 0,
optional unrestricted double y = 0,
optional unrestricted double z = 0,
optional unrestricted double angle = 0);
DOMMatrix skewXSelf(optional unrestricted double sx = 0);
DOMMatrix skewYSelf(optional unrestricted double sy = 0);
DOMMatrix invertSelf();
[Exposed=Window] DOMMatrix setMatrixValue(DOMString transformList);
};
dictionary DOMMatrixInit {
unrestricted double a;
unrestricted double b;
unrestricted double c;
unrestricted double d;
unrestricted double e;
unrestricted double f;
unrestricted double m11;
unrestricted double m12;
unrestricted double m13 = 0;
unrestricted double m14 = 0;
unrestricted double m21;
unrestricted double m22;
unrestricted double m23 = 0;
unrestricted double m24 = 0;
unrestricted double m31 = 0;
unrestricted double m32 = 0;
unrestricted double m33 = 1;
unrestricted double m34 = 0;
unrestricted double m41;
unrestricted double m42;
unrestricted double m43 = 0;
unrestricted double m44 = 1;
boolean is2D;
};
</pre>
<p>The following algorithms assume that {{DOMMatrixReadOnly}} objects have the internal member
variables <dfn dfn-for=matrix>m11 element</dfn>, <dfn dfn-for=matrix>m12 element</dfn>, <dfn
dfn-for=matrix>m13 element</dfn>, <dfn dfn-for=matrix>m14 element</dfn>, <dfn dfn-for=matrix>m21
element</dfn>, <dfn dfn-for=matrix>m22 element</dfn>, <dfn dfn-for=matrix>m23 element</dfn>, <dfn
dfn-for=matrix>m24 element</dfn>, <dfn dfn-for=matrix>m31 element</dfn>, <dfn dfn-for=matrix>m32
element</dfn>, <dfn dfn-for=matrix>m33 element</dfn>, <dfn dfn-for=matrix>m34 element</dfn>, <dfn
dfn-for=matrix>m41 element</dfn>, <dfn dfn-for=matrix>m42 element</dfn>, <dfn dfn-for=matrix>m43
element</dfn>, <dfn dfn-for=matrix>m44 element</dfn> and <a for=matrix>is 2D</a>.
{{DOMMatrixReadOnly}} as well as the inheriting interface {{DOMMatrix}} must be able to access and
set the value of these variables.
<p>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.
<p>Internal member variables must not be exposed in any way.
<p>The {{DOMMatrix}} and {{DOMMatrixReadOnly}} interfaces replace the <code>SVGMatrix</code>
interface from SVG. [[SVG11]]
<p>For historical reasons, {{Window}} objects must also have writable, configurable, non-enumerable
properties named <dfn dfn-type=interface><code>SVGMatrix</code></dfn> and <dfn
dfn-type=interface><code>WebKitCSSMatrix</code></dfn> whose value is the {{DOMMatrix}} interface
object.
<h3 id=dommatrixinit-dictionary>DOMMatrixInit dictionary</h3>
<p>To <dfn dfn-for=matrix>validate and fixup</dfn> a {{DOMMatrixInit}} dictionary <var>dict</var>,
run the following steps:
<ol>
<li>
<p>If if at least one of the following conditions are true for <var>dict</var>, throw a
{{TypeError}} exception and abort these steps.
<ul>
<li><p>{{DOMMatrixInit/a}} and {{DOMMatrixInit/m11}} are both present and their values are not
the <a for="WebIDL unrestricted double">same</a>.
<li><p>{{DOMMatrixInit/b}} and {{DOMMatrixInit/m12}} are both present and their values are not
the <a for="WebIDL unrestricted double">same</a>.
<li><p>{{DOMMatrixInit/c}} and {{DOMMatrixInit/m21}} are both present and their values are not
the <a for="WebIDL unrestricted double">same</a>.
<li><p>{{DOMMatrixInit/d}} and {{DOMMatrixInit/m22}} are both present and their values are not
the <a for="WebIDL unrestricted double">same</a>.
<li><p>{{DOMMatrixInit/e}} and {{DOMMatrixInit/m41}} are both present and their values are not
the <a for="WebIDL unrestricted double">same</a>.
<li><p>{{DOMMatrixInit/f}} and {{DOMMatrixInit/m42}} are both present and their values are not
the <a for="WebIDL unrestricted double">same</a>.
<li><p>{{DOMMatrixInit/is2D}} is <code>true</code> and at least one of {{DOMMatrixInit/m13}},
{{DOMMatrixInit/m14}}, {{DOMMatrixInit/m23}}, {{DOMMatrixInit/m24}}, {{DOMMatrixInit/m31}},
{{DOMMatrixInit/m32}}, {{DOMMatrixInit/m34}}, {{DOMMatrixInit/m43}} are present with a value
other than ''0'', or at least one of {{DOMMatrixInit/m33}}, {{DOMMatrixInit/m44}} are present
with a value other than ''1''.
</ul>
<li><p>If {{DOMMatrixInit/m11}} is not present then set it to the value of member
{{DOMMatrixInit/a}}, or value ''1'' if {{DOMMatrixInit/a}} is also not present.
<li><p>If {{DOMMatrixInit/m12}} is not present then set it to the value of member
{{DOMMatrixInit/b}}, or value ''0'' if {{DOMMatrixInit/b}} is also not present.
<li><p>If {{DOMMatrixInit/m21}} is not present then set it to the value of member
{{DOMMatrixInit/c}}, or value ''0'' if {{DOMMatrixInit/c}} is also not present.
<li><p>If {{DOMMatrixInit/m22}} is not present then set it to the value of member
{{DOMMatrixInit/d}}, or value ''1'' if {{DOMMatrixInit/d}} is also not present.
<li><p>If {{DOMMatrixInit/m41}} is not present then set it to the value of member
{{DOMMatrixInit/e}}, or value ''0'' if {{DOMMatrixInit/e}} is also not present.
<li><p>If {{DOMMatrixInit/m42}} is not present then set it to the value of member
{{DOMMatrixInit/f}}, or value ''0'' if {{DOMMatrixInit/f}} is also not present.
<li><p>If {{DOMMatrixInit/is2D}} is not present and at least one of {{DOMMatrixInit/m13}},
{{DOMMatrixInit/m14}}, {{DOMMatrixInit/m23}}, {{DOMMatrixInit/m24}}, {{DOMMatrixInit/m31}},
{{DOMMatrixInit/m32}}, {{DOMMatrixInit/m34}}, {{DOMMatrixInit/m43}} are present with a value other
than ''0'', or at least one of {{DOMMatrixInit/m33}}, {{DOMMatrixInit/m44}} are present with a
value other than ''1'', set {{DOMMatrixInit/is2D}} to <code>false</code>.
<li><p>If {{DOMMatrixInit/is2D}} is still not present, set it to <code>true</code>.
</ol>
<p>For the purpose of the algorithm above, two WebIDL unrestricted double values are the <dfn
for="WebIDL unrestricted double">same</dfn> if they have identical IEEE 754 double-precision bit
patterns.
<p class=note>This means that two ''NaN'' values are the <a for="WebIDL unrestricted
double">same</a>, but ''0'' and ''-0'' are not the <a for="WebIDL unrestricted double">same</a>.
<h3 id=dommatrix-create>Creating DOMMatrixReadOnly and DOMMatrix objects</h3>
<p>To <dfn>create a 2d matrix</dfn> of type <var>type</var> being either {{DOMMatrixReadOnly}} or
{{DOMMatrix}}, with a sequence <var>init</var> of 6 elements, follow these steps:
<ol>
<li><p>Let <var>matrix</var> be a new instance of <var>type</var>.
<li><p>Set <a for=matrix>m11 element</a>, <a for=matrix>m12 element</a>, <a for=matrix>m21
element</a>, <a for=matrix>m22 element</a>, <a for=matrix>m41 element</a> and <a for=matrix>m42
element</a> to the values of <var>init</var> in order starting with the first value.
<li><p>Set <a for=matrix>m13 element</a>, <a for=matrix>m14 element</a>, <a for=matrix>m23
element</a>, <a for=matrix>m24 element</a>, <a for=matrix>m31 element</a>, <a for=matrix>m32
element</a>, <a for=matrix>m34 element</a>, and <a for=matrix>m43 element</a> to ''0''.
<li><p>Set <a for=matrix>m33 element</a> and <a for=matrix>m44 element</a> to ''1''.
<li><p>Set <a for=matrix>is 2D</a> to <code>true</code>.
<li><p>Return <var>matrix</var>
</ol>
<p>To <dfn>create a 3d matrix</dfn> with <var>type</var> being either {{DOMMatrixReadOnly}} or
{{DOMMatrix}}, with a sequence <var>init</var> of 16 elements, follow these steps:
<ol>
<li><p>Let <var>matrix</var> be a new instance of <var>type</var>.
<li><p>Set <a for=matrix>m11 element</a> to <a for=matrix>m44 element</a> to the values of
<var>init</var> in column-major order.
<li><p>Set <a for=matrix>is 2D</a> to <code>false</code>.
<li><p>Return <var>matrix</var>
</ol>
<p>The <dfn dfn-type=constructor
dfn-for=DOMMatrixReadOnly><code>DOMMatrixReadOnly(<var>init</var>)</code></dfn> and the <dfn
dfn-type=constructor dfn-for=DOMMatrix><code>DOMMatrix(<var>init</var>)</code></dfn> constructors
must follow these steps:
<dl class=switch>
<dt>If <var>init</var> is omitted
<dd>Return the result of invoking <a>create a 2d matrix</a> of type {{DOMMatrixReadOnly}} or
{{DOMMatrix}} as appropriate, with the sequence [''1'', ''0'', ''0'', ''1'', ''0'', ''0''].
<dt>If <var>init</var> is a {{DOMString}}
<dd>
<ol>
<li><p>If <a>current global object</a> is not a {{Window}} object, then throw a {{TypeError}}
exception.
<li><p>If <var>init</var> is the empty string, set it to the string
"<code nohighlight>matrix(1, 0, 0, 1, 0, 0)</code>".
<li><p>Parse <var>init</var> into <var>parsedValue</var> by following the syntax description in
“<a href=https://drafts.csswg.org/css-transforms-1/#svg-syntax>Syntax of the SVG ‘transform’
attribute</a>” to a <<transform-list>> or the keyword ''transform/none''. If parsing is not
successful, or any <<transform-function>> has <<length>> values without <a
spec=css-values>absolute length</a> units<!--For WD: <a spec=css-values-3>absolute length
units</a>-->, or any keyword other than ''transform/none'' is used, throw a "{{SyntaxError}}"
{{DOMException}}. [[!CSS3-TRANSFORMS]]
<li><p>If <var>parsedValue</var> is ''transform/none'', set <var>parsedValue</var> to a
<<transform-list>> containing a single identity matrix
<li><p>Let <var>2dTransform</var> track the 2D/3D dimension status of <var>parsedValue</var>.
<dl class=switch>
<dt>If <var>parsedValue</var> consists of any <a
href="https://drafts.csswg.org/css-transforms-1/#three-d-transform-functions">3D Transform
functions</a>
<dd>Set <var>2dTransform</var> to <code>false</code>.
<dt>Otherwise
<dd>Set <var>2dTransform</var> to <code>true</code>.
</dl>
<li><p>Transform all <<transform-function>>s to 4x4 matrices by following the “<a
href=https://drafts.csswg.org/css-transforms-1/#mathematical-description>Mathematical
Description of Transform Functions</a>”. [[!CSS3-TRANSFORMS]]
<li><p>Let <var>matrix</var> be a 4x4 matrix as shown in the initial figure of this section. <a
for=matrix>Post-multiply</a> all matrices from left to right and set <var>matrix</var> to this
product.
<li>
<dl class=switch>
<dt>If <var>2dTransform</var> is set to <code>true</code>
<dd>Return the result of invoking <a>create a 2d matrix</a> of type {{DOMMatrixReadOnly}} or
{{DOMMatrix}} as appropriate, with a sequence of numbers, the values being the elements <var
ignore>m11</var>, <var ignore>m12</var>, <var ignore>m21</var>, <var ignore>m22</var>, <var
ignore>m41</var> and <var ignore>m42</var> of <var>matrix</var>.
<dt>If <var>2dTransform</var> is set to <code>false</code>
<dd>Return the result of invoking <a>create a 3d matrix</a> of type {{DOMMatrixReadOnly}} or
{{DOMMatrix}} as appropriate, with a sequence of numbers, the values being the 16 elements of
<var>matrix</var>.
</dl>
</ol>
<dt>If <var>init</var> is a sequence with 6 elements
<dd>Return the result of invoking <a>create a 2d matrix</a> of type {{DOMMatrixReadOnly}} or
{{DOMMatrix}} as appropriate, with the sequence <var>init</var>.
<dt>If <var>init</var> is a sequence with 16 elements
<dd>Return the result of invoking <a>create a 3d matrix</a> of type {{DOMMatrixReadOnly}} or
{{DOMMatrix}} as appropriate, with the sequence <var>init</var>.
<dt>Otherwise
<dd>Throw a {{TypeError}} exception.
</dl>