-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validator - check that RGBA/RGB/RGB565/CONSTANT_RGBA are in range #121
Conversation
validator/lib/validatePnts.js
Outdated
if (defined(featureTableJson.RGBA)) { | ||
featureTable.featuresLength = pointsLength * 4; | ||
componentDatatype = ComponentDatatype.fromName(defaultValue(featureTableJson.RGBA.componentType, 'UNSIGNED_SHORT', 4)); | ||
var rgba = featureTable.getPropertyArray('RGBA', componentDatatype, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -257,4 +257,169 @@ describe('validate pnts', function() { | |||
}); | |||
expect(validatePnts(pnts)).toBeUndefined(); | |||
}); | |||
|
|||
it('returns error message when RGBA is out of range [Test using feature table JSON]', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a test for when it succeeds?
validator/lib/validatePnts.js
Outdated
@@ -196,6 +198,42 @@ function validatePnts(content) { | |||
} | |||
} | |||
|
|||
if (defined(featureTableJson.RGBA)) { | |||
featureTable.featuresLength = pointsLength * 4; | |||
componentDatatype = ComponentDatatype.fromName(defaultValue(featureTableJson.RGBA.componentType, 'UNSIGNED_SHORT', 4)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UNSIGNED_SHORT
should be UNISNGED_BYTE
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the , 4
at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have purposely set the parameter to UNSIGNED_SHORT
. When I set it to UNSIGNED_BYTE
, the values, if out of range, will be clipped when creating an array using featureTable.getPropertyArray()
. So I am using higher precision type to catch invalid values. Same for the other checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may have talked about this offline before.... but here are my latest thoughts: using a higher precision is unsafe because it distorts the values that are retrieved from the feature table binary and may result in out-of-bounds issues. Ultimately these range checks for colors are not super useful for binary properties, but are helpful for array-based properties.
validator/lib/validatePnts.js
Outdated
} | ||
} else if (defined(featureTableJson.RGB)) { | ||
featureTable.featuresLength = pointsLength * 3; | ||
componentDatatype = ComponentDatatype.fromName(defaultValue(featureTableJson.RGB.componentType, 'UNSIGNED_SHORT', 3)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be UNSIGNED_BYTE
.
validator/lib/validatePnts.js
Outdated
} | ||
} else if (defined(featureTableJson.RGB565)) { | ||
featureTable.featuresLength = pointsLength; | ||
componentDatatype = ComponentDatatype.fromName(defaultValue(featureTableJson.RGB565.componentType, 'UNSIGNED_INT', 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be UNSIGNED_SHORT
.
@lilleyse Should be good now. |
fixes #119
Checks that the values of RGBA (array), RGB (array) and CONSTANT_RGBA are between 0-255, and that the values of RGB565 (array) are between 0-65535.