phetsims/dot

Vector2 serialization should use NumberIO

Closed this issue · 4 comments

And also Vector3!

So now I have
image

@jonathanolson please review.

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.

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 phetsims/tandem#280. @zepumph can this be closed?