Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

rms13
Copy link
Contributor

@rms13 rms13 commented Aug 10, 2017

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.

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);
Copy link
Contributor

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() {
Copy link
Contributor

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?

@@ -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));
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

}
} else if (defined(featureTableJson.RGB)) {
featureTable.featuresLength = pointsLength * 3;
componentDatatype = ComponentDatatype.fromName(defaultValue(featureTableJson.RGB.componentType, 'UNSIGNED_SHORT', 3));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be UNSIGNED_BYTE.

}
} else if (defined(featureTableJson.RGB565)) {
featureTable.featuresLength = pointsLength;
componentDatatype = ComponentDatatype.fromName(defaultValue(featureTableJson.RGB565.componentType, 'UNSIGNED_INT', 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be UNSIGNED_SHORT.

@rms13
Copy link
Contributor Author

rms13 commented Sep 5, 2017

@lilleyse Should be good now.

@lilleyse lilleyse closed this Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants