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

color does not enforce refinements #487

Closed
schanzer opened this issue Oct 4, 2023 · 3 comments
Closed

color does not enforce refinements #487

schanzer opened this issue Oct 4, 2023 · 3 comments

Comments

@schanzer
Copy link

schanzer commented Oct 4, 2023

The Color library includes the color constructor, whose documentation says the first three inputs should all be numbers between 0-255 (inclusive). However, calling the function with numbers outside of that range seems to work just fine.

This is either a bug in the implementation or the documentation. I'm inclined to say the implementation should conform to the documentation.

@asolove
Copy link
Contributor

asolove commented Mar 12, 2024

Currently, I think color is defined as a plain data constructor with no refinements on the values allowed:

data Color:
  | color(
      red :: Number,
      green :: Number,
      blue :: Number,
      alpha :: Number)
end

-- https://github.com/brownplt/code.pyret.org/blob/horizon/src/web/arr/trove/color.arr#L9

and then code that interprets colors is clamping the RGB values when it interprets them.


If we want to make the runtime behavior match the docs, and throw an error when the values are outside of bounds, then we can add a refinement check on the color constructor. I'll make a PR for that, though it has some possible impacts it's hard for me to guess.

asolove added a commit to asolove/code.pyret.org that referenced this issue Mar 13, 2024
Resolves brownplt#487.

The author has checked that this works in basic cases, but isn't sure this is safe all the time. (Are there programs that currently rely on the clamping error, that this will cause to error?)
@blerner
Copy link
Member

blerner commented Mar 13, 2024

Neither. We discussed this a long time ago: there is potential mathematical value in having denormalized numbers. (If we ever wanted to do an optics-related unit, say, where we wanted to understand additive color, then we'd like to say "red + yellow = yellow", because even though you have more red than before you can't see it, it's too bright. Similarly subtractive color should allow for negative values, that get clamped to zero analogously.) We stuck with the documentation as is for now, so that only highly-exploratory students might encounter it; otherwise, it would be moot.

@schanzer
Copy link
Author

@blerner whoa - that is a really interesting explanation. I don't think any teacher who doesn't already know you and Joe would ever think of that. Could we add that to the documentation, and then close this issue?

blerner pushed a commit to brownplt/pyret-docs that referenced this issue May 2, 2024
@blerner blerner closed this as completed May 2, 2024
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 a pull request may close this issue.

3 participants