phetsims / dot

A math library with a focus on mutable and immutable linear algebra for 2D and 3D applications.
MIT License
13 stars 6 forks source link

Vector2 serialization should use NumberIO #110

Closed zepumph closed 1 year ago

zepumph commented 3 years ago

from https://github.com/phetsims/tandem/issues/246

zepumph commented 3 years ago

And also Vector3!

zepumph commented 3 years ago

So now I have image

@jonathanolson please review.

zepumph commented 3 years ago

Also note that I could have deleted the toSateObject function in exchange for the default coming from stateSchema, but I thought it was worth having around so people can call serialization directly on the Vector2 instance, instead of needing to go through the IO type.

samreid commented 1 year ago

I now see this behavior:

phet.dot.Vector2.Vector2IO.toStateObject(new phet.dot.Vector2(Number.POSITIVE_INFINITY,0));

assert.js:24 Assertion failed:  validation failed: value failed isValidValue: Infinity prunedValidator: {isValidValue: ƒ}
assert.js:28 Uncaught Error: Assertion failed: validation failed:
 value failed isValidValue: Infinity
 prunedValidator:
 [object Object]
    at window.assertions.assertFunction (assert.js:28:13)
    at validate (validate.ts:26:17)
    at StateSchema.checkStateObjectValid (StateSchema.ts:208:9)
    at IOType.isStateObjectValid (IOType.ts:404:43)
    at IOType.validateStateObject (IOType.ts:444:10)
    at StateSchema.ts:195:30
    at Array.forEach (<anonymous>)
    at checkLevel (StateSchema.ts:189:77)
    at StateSchema.checkStateObjectValid (StateSchema.ts:200:7)
    at IOType.isStateObjectValid (IOType.ts:404:43)

When I disabled assertions, I got:

{x: Infinity, y: 0}

I think this is in line with https://github.com/phetsims/tandem/issues/280. @zepumph can this be closed?