object: do not panic on a sampled function with an inverted /Domain - #296
Open
apollo-2006 wants to merge 1 commit into
Open
apollo-2006 wants to merge 1 commit into
apollo-2006 wants to merge 1 commit into
Conversation
f32::clamp panics when min > max, and /Domain is used as written in the file, so evaluating a Type 0 function with /Domain [10 1] panicked. Order the bounds before clamping, as the stitching function does. Fixes pdf-rs#288
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SampledFunctionInput::mapclamps its input withx.clamp(self.domain.0, self.domain.1), andf32::clamppanics when the lower bound is greater than the upper one./Domainis used as written in the file, so a Type 0 function with/Domain [10 1], like the one attached to #288, panics as soon as it is evaluated.This orders the bounds before clamping, the same way
StitchingFunction::applyalready does. The issue suggests rejecting such a function when it is loaded instead. I went with the lenient version to match the stitching function, but I am happy to switch to the strict one if you prefer it.Testing:
object::function::testsbuilds a two-sample ramp with/Domain [1 0]throughFunction::from_primitiveand evaluates it at points inside and outside the domain. Without the change it panics withmin > max, or either was NaN. min = 1.0, max = 0.0.cargo test --workspacepasses.While testing I noticed a separate problem:
mapapplies/Encodeasx * Encode[1] + Encode[0], without taking/Domaininto account. The spec maps the domain onto the encode range, so a well-formed two-sample ramp with/Domain [0 2]gives 1.0 at x = 1 where it should give 0.5. That one affects valid files, so I have left it out of this PR and can send it separately.Fixes #288