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

Fixed tritanopia simulation #525

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

williamjsdavis
Copy link
Contributor

Summary: Fixed a typo causing incorrect simulation of tritanopic color vision deficiencies. Also added tests for this corrected behavior.

This is my first pull request, I apologize if I have done anything incorrectly. I have been working with simulating various color vision deficiencies, and I noticed that the simulation for tritanopia was not producing results that I expected. Looking into the code in the function tritanopic had a typo:

(one(p) - p) * q.l + p * (-(a*q.l + b*q.m)/c))

It should be:

(one(p) - p) * q.s + p * (-(a*q.l + b*q.m)/c))

This error can be easily observed when inspecting the behavior of the function at p=0 (no photopigment loss):

Screen Shot 2022-09-30 at 13 20 03

This can also be seen in the RGB values:

rgb = RGB(0.44, 0.26, 0.8)
rgb |> dump
tritanopic(rgb, 0) |> dump
RGB{Float64}
  r: Float64 0.44
  g: Float64 0.26
  b: Float64 0.8
RGB{Float64}
  r: Float64 0.4547022003851215
  g: Float64 0.2596348656158941
  b: Float64 0.33903165107645483

As a counterexample, the function protanopic is working correctly:

Screen Shot 2022-09-30 at 13 20 51

rgb = RGB(0.44, 0.26, 0.8)
rgb |> dump
protanopic(rgb, 0) |> dump
RGB{Float64}
  r: Float64 0.44
  g: Float64 0.26
  b: Float64 0.8
RGB{Float64}
  r: Float64 0.4400000030003578
  g: Float64 0.26000003129854465
  b: Float64 0.8000000074911268

This pull request fixes this typo, and adds three tests to validate this correct behavior. Please let me know if there are any questions.

Fixed a typo causing incorrect simulation of tritanopic color vision deficiencies. Also added tests for this corrected behavior
@codecov
Copy link

codecov bot commented Sep 30, 2022

Codecov Report

Base: 94.33% // Head: 95.51% // Increases project coverage by +1.18% 🎉

Coverage data is based on head (d117720) compared to base (b550b7b).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #525      +/-   ##
==========================================
+ Coverage   94.33%   95.51%   +1.18%     
==========================================
  Files           9        9              
  Lines        1270     1270              
==========================================
+ Hits         1198     1213      +15     
+ Misses         72       57      -15     
Impacted Files Coverage Δ
src/algorithms.jl 91.96% <ø> (+16.07%) ⬆️
src/utilities.jl 95.60% <0.00%> (-0.74%) ⬇️
src/conversions.jl 99.13% <0.00%> (-0.29%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@johnnychen94 johnnychen94 merged commit dc6438f into JuliaGraphics:master Dec 13, 2022
johnnychen94 pushed a commit that referenced this pull request Dec 15, 2022
Fixed a typo causing incorrect simulation of tritanopic color vision deficiencies. Also added tests for this corrected behavior
Comment on lines +61 to +63
@test protanopic(rgb, 0) .≈ rgb
@test deuteranopic(rgb, 0) .≈ rgb
@test tritanopic(rgb, 0) .≈ rgb
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is ok, but why .≈?

Algorithms: Test Failed at ~\.julia\dev\Colors\test\algorithms.jl:61
  Expression: protanopic(rgb, 0) .≈ rgb

Stacktrace:

More informative

Algorithms: Test Failed at ~\.julia\dev\Colors\test\algorithms.jl:61
  Expression: protanopic(rgb, 0)  rgb
   Evaluated: RGB{Float64}(0.4400000030003578,0.26000003129854465,0.8000000074911268)  RGB{Float64}(0.44,0.26,0.8)

Stacktrace:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right in highlighting that the use of .≈ is not ideal. Instead, should be used with an appropriate tolerance accounting for the small floating point errors introduced in the calculation.

@kimikage kimikage mentioned this pull request May 14, 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 this pull request may close these issues.

3 participants