mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 01:02:45 +00:00 
			
		
		
		
	LibWeb: Add DOMMatrix toFloat32Array and toFloat64Array
This commit is contained in:
		
							parent
							
								
									7b4b5b735b
								
							
						
					
					
						commit
						2e122b16e4
					
				
					 6 changed files with 59 additions and 2 deletions
				
			
		|  | @ -5,6 +5,8 @@ | |||
|  * SPDX-License-Identifier: BSD-2-Clause | ||||
|  */ | ||||
| 
 | ||||
| #include <LibJS/Runtime/ArrayBuffer.h> | ||||
| #include <LibJS/Runtime/TypedArray.h> | ||||
| #include <LibWeb/Bindings/Intrinsics.h> | ||||
| #include <LibWeb/Geometry/DOMMatrix.h> | ||||
| #include <LibWeb/Geometry/DOMMatrixReadOnly.h> | ||||
|  | @ -453,6 +455,32 @@ JS::NonnullGCPtr<DOMPoint> DOMMatrixReadOnly::transform_point(DOMPointReadOnly c | |||
|     return DOMPoint::construct_impl(realm(), point_vector.x(), point_vector.y(), point_vector.z(), point_vector.w()); | ||||
| } | ||||
| 
 | ||||
| // https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-tofloat32array
 | ||||
| JS::NonnullGCPtr<JS::Float32Array> DOMMatrixReadOnly::to_float32_array() const | ||||
| { | ||||
|     // Returns the serialized 16 elements m11 to m44 of the current matrix in column-major order as Float32Array.
 | ||||
|     float elements[16] = { static_cast<float>(m11()), static_cast<float>(m12()), static_cast<float>(m13()), static_cast<float>(m14()), | ||||
|         static_cast<float>(m21()), static_cast<float>(m22()), static_cast<float>(m23()), static_cast<float>(m24()), | ||||
|         static_cast<float>(m31()), static_cast<float>(m32()), static_cast<float>(m33()), static_cast<float>(m34()), | ||||
|         static_cast<float>(m41()), static_cast<float>(m42()), static_cast<float>(m43()), static_cast<float>(m44()) }; | ||||
|     auto bytes = MUST(ByteBuffer::copy(elements, sizeof(elements))); | ||||
|     auto array_buffer = JS::ArrayBuffer::create(realm(), move(bytes)); | ||||
|     return JS::Float32Array::create(realm(), sizeof(elements) / sizeof(float), array_buffer); | ||||
| } | ||||
| 
 | ||||
| // https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-tofloat64array
 | ||||
| JS::NonnullGCPtr<JS::Float64Array> DOMMatrixReadOnly::to_float64_array() const | ||||
| { | ||||
|     // Returns the serialized 16 elements m11 to m44 of the current matrix in column-major order as Float64Array.
 | ||||
|     double elements[16] = { m11(), m12(), m13(), m14(), | ||||
|         m21(), m22(), m23(), m24(), | ||||
|         m31(), m32(), m33(), m34(), | ||||
|         m41(), m42(), m43(), m44() }; | ||||
|     auto bytes = MUST(ByteBuffer::copy(elements, sizeof(elements))); | ||||
|     auto array_buffer = JS::ArrayBuffer::create(realm(), move(bytes)); | ||||
|     return JS::Float64Array::create(realm(), sizeof(elements) / sizeof(double), array_buffer); | ||||
| } | ||||
| 
 | ||||
| // https://drafts.fxtf.org/geometry/#dommatrixreadonly-stringification-behavior
 | ||||
| WebIDL::ExceptionOr<String> DOMMatrixReadOnly::to_string() const | ||||
| { | ||||
|  |  | |||
|  | @ -101,6 +101,8 @@ public: | |||
| 
 | ||||
|     JS::NonnullGCPtr<DOMPoint> transform_point(DOMPointInit const&) const; | ||||
|     JS::NonnullGCPtr<DOMPoint> transform_point(DOMPointReadOnly const&) const; | ||||
|     JS::NonnullGCPtr<JS::Float32Array> to_float32_array() const; | ||||
|     JS::NonnullGCPtr<JS::Float64Array> to_float64_array() const; | ||||
| 
 | ||||
|     WebIDL::ExceptionOr<String> to_string() const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -54,8 +54,8 @@ interface DOMMatrixReadOnly { | |||
|     [NewObject] DOMMatrix inverse(); | ||||
| 
 | ||||
|     [NewObject] DOMPoint transformPoint(optional DOMPointInit point = {}); | ||||
|     // FIXME: [NewObject] Float32Array toFloat32Array(); | ||||
|     // FIXME: [NewObject] Float64Array toFloat64Array(); | ||||
|     [NewObject] Float32Array toFloat32Array(); | ||||
|     [NewObject] Float64Array toFloat64Array(); | ||||
| 
 | ||||
|     [Exposed=Window] stringifier; | ||||
|     [Default] object toJSON(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Bastiaan van der Plaat
						Bastiaan van der Plaat