jsdom,builtin: add all methods for DOMMatrix; add conversion methods to convet from/to JS types (#12395)

pull/12404/head
playX 2021-11-06 16:52:24 +03:00 committed by GitHub
parent 7a9ba9f41f
commit 5f3dcde358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 431 additions and 64 deletions

View File

@ -104,3 +104,66 @@ pub fn (f float_literal) str() string {
return res
}
pub fn tof64(n JS.Number) f64 {
res := f64(0.0)
#res.val = n;
return res
}
pub fn tof32(n JS.Number) f32 {
res := f32(0.0)
#res.val = n;
return res
}
pub fn toi(n JS.Number) int {
res := int(0)
#res.val = Math.floor(n);
return res
}
pub fn f64tonum(n f64) JS.Number {
mut res := JS.Number{}
#res = n.val;
return res
}
pub fn itonum(n int) JS.Number {
mut res := JS.Number{}
#res = n.val;
return res
}
pub fn i64tobigint(n i64) JS.BigInt {
mut res := JS.BigInt{}
#res = n.val;
return res
}
pub fn u64tobigint(n u64) JS.BigInt {
mut res := JS.BigInt{}
#res = n.val;
return res
}
pub fn tobool(b JS.Boolean) bool {
res := false
#res.val = b;
return res
}
pub fn booltojs(b bool) JS.Boolean {
mut res := JS.Boolean{}
#res = b.val;
return res
}

View File

@ -7,6 +7,8 @@
module builtin
pub struct JS.BigInt {}
pub struct JS.Number {}
pub struct JS.String {

View File

@ -184,67 +184,3 @@ fn init() {
#jsdom__document.node = document;
#jsdom__window.node = window;
}
pub struct JS.DOMMatrix {
pub:
is_2d JS.Boolean [noinit]
is_identity JS.Boolean [noinit]
pub mut:
m11 JS.Number [noinit]
m12 JS.Number [noinit]
m13 JS.Number [noinit]
m14 JS.Number [noinit]
m21 JS.Number [noinit]
m22 JS.Number [noinit]
m23 JS.Number [noinit]
m24 JS.Number [noinit]
m31 JS.Number [noinit]
m32 JS.Number [noinit]
m33 JS.Number [noinit]
m34 JS.Number [noinit]
m41 JS.Number [noinit]
m42 JS.Number [noinit]
m43 JS.Number [noinit]
m44 JS.Number [noinit]
a JS.Number [noinit]
b JS.Number [noinit]
c JS.Number [noinit]
d JS.Number [noinit]
e JS.Number [noinit]
f JS.Number [noinit]
}
pub struct DOMMatrix {
matrix JS.DOMMatrix [noinit]
}
pub fn (matrix DOMMatrix) str() string {
fmt := ''
#fmt.str = matrix.matrix + ''
return fmt
}
pub fn new_matrix(init []f64) DOMMatrix {
#let tmp = new Array();
for val in init {
_ := val
#tmp.push(val);
}
mut m := JS.DOMMatrix{}
#m = new DOMMatrix(tmp);
return DOMMatrix{m}
}
pub fn (m DOMMatrix) invert_self() {
#m.matrix.invertSelf();
}
pub fn (m DOMMatrix) is_2d() bool {
res := false
#res.val = m.matrix.is2D.val;
return res
}

View File

@ -0,0 +1,366 @@
module jsdom
pub struct JS.DOMMatrix {
pub:
is_2d JS.Boolean [noinit]
is_identity JS.Boolean [noinit]
pub mut:
m11 JS.Number [noinit]
m12 JS.Number [noinit]
m13 JS.Number [noinit]
m14 JS.Number [noinit]
m21 JS.Number [noinit]
m22 JS.Number [noinit]
m23 JS.Number [noinit]
m24 JS.Number [noinit]
m31 JS.Number [noinit]
m32 JS.Number [noinit]
m33 JS.Number [noinit]
m34 JS.Number [noinit]
m41 JS.Number [noinit]
m42 JS.Number [noinit]
m43 JS.Number [noinit]
m44 JS.Number [noinit]
a JS.Number [noinit]
b JS.Number [noinit]
c JS.Number [noinit]
d JS.Number [noinit]
e JS.Number [noinit]
f JS.Number [noinit]
}
pub struct DOMMatrix {
mut:
matrix JS.DOMMatrix [noinit]
}
pub fn (matrix DOMMatrix) str() string {
fmt := ''
#fmt.str = matrix.matrix + ''
return fmt
}
pub fn new_matrix(init []f64) DOMMatrix {
#let tmp = new Array();
for val in init {
_ := val
#tmp.push(val);
}
mut m := JS.DOMMatrix{}
#m = new DOMMatrix(tmp);
return DOMMatrix{m}
}
pub fn (m DOMMatrix) invert_self() {
#m.matrix.invertSelf();
}
pub fn (m DOMMatrix) multiply_self(other DOMMatrix) {
#m.matrix.multiplySelf(other.matrix);
}
pub fn (m DOMMatrix) pre_multiply_self(other DOMMatrix) {
#m.matrix.preMultiplySelf(other.matrix);
}
pub fn (m DOMMatrix) translate_self(tx f64, ty f64, tz f64) {
#m.matrix.translateSelf(tx.val,ty.val,tz.val);
}
pub fn (m DOMMatrix) scale3d_self(scale f64, origin_x f64, origin_y f64, origin_z f64) {
#m.matrix.scale3dSelf(scale.val,origin_x.val,origin_y.val,origin_z.val)
}
pub fn (m DOMMatrix) scale_self(scale_x f64, scale_y f64, scale_z f64, origin_x f64, origin_y f64, origin_z f64) {
#m.matrix.scaleSelf(scale_x.val,scale_y.val,scale_z.val,origin_x.val,origin_y.val,origin_z.val);
}
pub fn (m DOMMatrix) rotate_self(rot_x f64, rot_y f64, rot_z f64) {
#m.matrix.rotateSelf(rot_x.val,rot_y.val,rot_z.val);
}
pub fn (m DOMMatrix) rotate_axis_angle_self(x f64, y f64, z f64, angle f64) {
#m.matrix.rotateAxisAngleSelf(x.val,y.val,z.val,angle.val);
}
pub fn (m DOMMatrix) rotate_from_vector_self(x f64, y f64) {
#m.matrix.rotateFromVectorSelf(x.val,y.val);
}
pub fn (m DOMMatrix) skew_x_self(sx f64) {
#m.matrix.skewXSelf(sx.val);
}
pub fn (m DOMMatrix) skew_y_self(sy f64) {
#m.matrix.skewYSelf(sy.val);
}
pub fn (m DOMMatrix) flip_x() DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.flipX();
return res
}
pub fn (m DOMMatrix) flip_y() DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.flipY();
return res
}
pub fn (m DOMMatrix) inverse() DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.inverse();
return res
}
pub fn (m DOMMatrix) multiply(other DOMMatrix) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.multiply(other.matrix);
return res
}
pub fn (m DOMMatrix) rotate(rot_x f64, rot_y f64, rot_z f64) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.rotate(rot_x.val,rot_y.val,rot_z.val);
return res
}
pub fn (m DOMMatrix) rotate_axis_angle(x f64, y f64, z f64, angle f64) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.rotateAxisAngle(x.val,y.val,z.val,angle.val);
return res
}
pub fn (m DOMMatrix) rotate_from_vector(x f64, y f64) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.rotateFromVector(x.val,y.val);
return res
}
pub fn (m DOMMatrix) scale(scale_x f64, scale_y f64, scale_z f64, origin_x f64, origin_y f64, origin_z f64) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.scale(scale_x.val,scale_y.val,scale_z.val,origin_x.val,origin_y.val,origin_z.val);
return res
}
pub fn (m DOMMatrix) scale3d(scale f64, origin_x f64, origin_y f64, origin_z f64) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.scale3d(scale.val, origin_x.val,origin_y.val,origin_z.val);
return res
}
pub fn (m DOMMatrix) skew_x(sx f64) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.skewX(sx.val);
return res
}
pub fn (m DOMMatrix) skew_y(sy f64) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.skewY(sy.val);
return res
}
pub fn (m DOMMatrix) translate(tx f64, ty f64, tz f64) DOMMatrix {
res := DOMMatrix{}
#res.matrix = m.matrix.translate(tx.val,ty.val,tz.val);
return res
}
pub fn (m DOMMatrix) is_2d() bool {
res := false
#res.val = m.matrix.is2D.val;
return res
}
pub fn (m DOMMatrix) a() f64 {
return tof64(m.matrix.a)
}
pub fn (m DOMMatrix) b() f64 {
return tof64(m.matrix.b)
}
pub fn (m DOMMatrix) c() f64 {
return tof64(m.matrix.c)
}
pub fn (m DOMMatrix) d() f64 {
return tof64(m.matrix.d)
}
pub fn (m DOMMatrix) e() f64 {
return tof64(m.matrix.e)
}
pub fn (m DOMMatrix) f() f64 {
return tof64(m.matrix.f)
}
pub fn (mut m DOMMatrix) set_a(a f64) {
m.matrix.a = f64tonum(a)
}
pub fn (mut m DOMMatrix) set_b(b f64) {
m.matrix.b = f64tonum(b)
}
pub fn (mut m DOMMatrix) set_c(c f64) {
m.matrix.c = f64tonum(c)
}
pub fn (mut m DOMMatrix) set_d(d f64) {
m.matrix.d = f64tonum(d)
}
pub fn (mut m DOMMatrix) set_e(e f64) {
m.matrix.e = f64tonum(e)
}
pub fn (mut m DOMMatrix) set_f(f f64) {
m.matrix.f = f64tonum(f)
}
pub fn (m DOMMatrix) m11() f64 {
return tof64(m.matrix.m11)
}
pub fn (m DOMMatrix) m12() f64 {
return tof64(m.matrix.m12)
}
pub fn (m DOMMatrix) m13() f64 {
return tof64(m.matrix.m13)
}
pub fn (m DOMMatrix) m14() f64 {
return tof64(m.matrix.m14)
}
pub fn (m DOMMatrix) m21() f64 {
return tof64(m.matrix.m21)
}
pub fn (m DOMMatrix) m22() f64 {
return tof64(m.matrix.m22)
}
pub fn (m DOMMatrix) m23() f64 {
return tof64(m.matrix.m23)
}
pub fn (m DOMMatrix) m24() f64 {
return tof64(m.matrix.m24)
}
pub fn (m DOMMatrix) m31() f64 {
return tof64(m.matrix.m31)
}
pub fn (m DOMMatrix) m32() f64 {
return tof64(m.matrix.m32)
}
pub fn (m DOMMatrix) m33() f64 {
return tof64(m.matrix.m33)
}
pub fn (m DOMMatrix) m34() f64 {
return tof64(m.matrix.m34)
}
pub fn (m DOMMatrix) m41() f64 {
return tof64(m.matrix.m41)
}
pub fn (m DOMMatrix) m42() f64 {
return tof64(m.matrix.m42)
}
pub fn (m DOMMatrix) m43() f64 {
return tof64(m.matrix.m43)
}
pub fn (m DOMMatrix) m44() f64 {
return tof64(m.matrix.m44)
}
pub fn (mut m DOMMatrix) set_m11(x f64) {
m.matrix.m11 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m12(x f64) {
m.matrix.m12 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m13(x f64) {
m.matrix.m13 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m14(x f64) {
m.matrix.m14 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m21(x f64) {
m.matrix.m21 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m22(x f64) {
m.matrix.m22 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m23(x f64) {
m.matrix.m23 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m24(x f64) {
m.matrix.m24 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m31(x f64) {
m.matrix.m31 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m32(x f64) {
m.matrix.m32 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m33(x f64) {
m.matrix.m33 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m34(x f64) {
m.matrix.m34 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m41(x f64) {
m.matrix.m41 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m42(x f64) {
m.matrix.m42 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m43(x f64) {
m.matrix.m43 = f64tonum(x)
}
pub fn (mut m DOMMatrix) set_m44(x f64) {
m.matrix.m44 = f64tonum(x)
}