Skip to content

Added algorithm for color contrast ratio. #1794

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

Merged
merged 17 commits into from
Feb 27, 2021
Merged

Added algorithm for color contrast ratio. #1794

merged 17 commits into from
Feb 27, 2021

Conversation

SethFalco
Copy link
Contributor

Describe your change:

This implements the procedure documented on the W3 website to calculate the contrast ratio between two colors.
https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-procedure

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

References

N/A

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Java files are placed inside an existing directory.
  • All filenames are in all uppercase characters with no spaces or dashes.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.

@SethFalco
Copy link
Contributor Author

SethFalco commented Nov 5, 2020

I'm closing this as I've replaced it with #2023 which merges to Development instead and includes unit tests.

@SethFalco SethFalco closed this Nov 5, 2020
@SethFalco SethFalco reopened this Feb 27, 2021
@ayaankhan98
Copy link
Member

would you please remove convolutionFFT.java from this PR, as this file is not related to this PR.

@SethFalco
Copy link
Contributor Author

would you please remove convolutionFFT.java from this PR, as this file is not related to this PR.

I could try, but that was the Google Java Formatter that did that, not me.
If I undo it, won't it just format it again?

@ayaankhan98
Copy link
Member

would you please remove convolutionFFT.java from this PR, as this file is not related to this PR.

I could try, but that was the Google Java Formatter that did that, not me.
If I undo it, won't it just format it again?

it is weird, Fromatter will format only those files which are linked to the PR. If it starts formatting files which are not linked in PR then there are so many files in the repository which are not up to standard, it would have formatted all of them.

Well try to remove this from this PR.

@SethFalco
Copy link
Contributor Author

SethFalco commented Feb 27, 2021

I removed both DIRECTORY.md and ConvolutionFFT.java , however it seems the bot decided to apply the formatting to ConvolutionFFT.java again, and also split up the markdown in the javadocs. 🤔

@ayaankhan98
Copy link
Member

I removed both DIRECTORY.md and ConvolutionFFT.java , however it seems the bot decided to apply the formatting to ConvolutionFFT.java again, and also split up the markdown in the javadocs. 🤔

How did you removed ConvolutionFFt.java from PR?

@SethFalco
Copy link
Contributor Author

How did you removed ConvolutionFFt.java from PR?

I just did git checkout origin/master -- Maths/ConvolutionFFT.java to revert it back to the version in master.

@ayaankhan98
Copy link
Member

How did you removed ConvolutionFFt.java from PR?

I just did git checkout origin/master -- Maths/ConvolutionFFT.java to revert it back to the version in master.

🤔 try git restore <path to file>

@SethFalco
Copy link
Contributor Author

thinking try git restore <path to file>

Tried it, however no changes were made, no files were staged, and git log doesn't return any new commits.
It appears to have done nothing.

Copy link
Member

@ayaankhan98 ayaankhan98 left a comment

Choose a reason for hiding this comment

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

Please add a test function to verify the implementation, rest of the code looks good to me.

@SethFalco
Copy link
Contributor Author

Please add a test function to verify the implementation, rest of the code looks good to me.

Just checking, is there a section for unit tests?
This PR already has a main method that should be valid.

public static void main(String args[]) {
  final ColorContrastRatio algorithmImpl = new ColorContrastRatio();

  // Relative Luminance: 0.12215748057375966
  final Color foreground = new Color(23, 103, 154);

  // Relative Luminance: 0.7898468477881603
  final Color background = new Color(226, 229, 248);

  // Contrast Ratio: 4.878363954846178
  final double contrastRatio = algorithmImpl.getContrastRatio(foreground, background);

  System.out.println(contrastRatio);
}

Looking at other classes, this appears to be how they're testing it also.

@SethFalco
Copy link
Contributor Author

May I also ask, you requested some javadocs have @brief prepended to them, but I'm unfamiliar with it, and can't see any other uses of it throughout the repository.

Could you explain why you wanted this or what it does?

@ayaankhan98
Copy link
Member

Please add a test function to verify the implementation, rest of the code looks good to me.

Just checking, is there a section for unit tests?
This PR already has a main method that should be valid.

public static void main(String args[]) {
  final ColorContrastRatio algorithmImpl = new ColorContrastRatio();

  // Relative Luminance: 0.12215748057375966
  final Color foreground = new Color(23, 103, 154);

  // Relative Luminance: 0.7898468477881603
  final Color background = new Color(226, 229, 248);

  // Contrast Ratio: 4.878363954846178
  final double contrastRatio = algorithmImpl.getContrastRatio(foreground, background);

  System.out.println(contrastRatio);
}

Looking at other classes, this appears to be how they're testing it also.

yes, i know it does have a main method. what i want to say is that, create a member function with name tests.

void test() {
      final ColorContrastRatio algorithmImpl = new ColorContrastRatio();
      // test 1
      final Color foreground = new Color(23, 103, 154);
      final Color background = new Color(226, 229, 248);
      final double contrastRatio = algorithmImpl.getContrastRatio(foreground, background);
      assert contrastRation == 4.878363954846178 : "Failed test 1";
      // test 2
      ..............................
      ..............................
      .............................
}
public static void main(String [] args) {
     // call test() here to execute test.
}

@ayaankhan98
Copy link
Member

May I also ask, you requested some javadocs have @brief prepended to them, but I'm unfamiliar with it, and can't see any other uses of it throughout the repository.

Could you explain why you wanted this or what it does?

Currently this repository is not up to a good standard, I am planing to improve this repository as we did in C++ repository. The reason i am enforcing javadocs style is, with the help of javadocs we can generate documentation for this repository automatically. Other files are not mainted properly, we will be improving them soon.

please have a look here https://thealgorithms.github.io/C-Plus-Plus/ (this is the documentaion of C++ repository algorithms, it is generated automatically using Doxygen)
this is what i am thinking to do with this repo too.

@ayaankhan98
Copy link
Member

Soon we will be updating the contribution guidelines so that people will follow proper guildelines for each and every PR. Thereby facilitating faster reviews and less burden on Maintainers and Contributors.

@SethFalco
Copy link
Contributor Author

yes, i know it does have a main method. what i want to say is that, create a member function with name tests.

Understood, thanks for clarifying, I believe I've done this now.

please have a look here https://thealgorithms.github.io/C-Plus-Plus/ (this is the documentaion of C++ repository algorithms, it is generated automatically using Doxygen)

Ahh I see, I wasn't familiar with Doxygen before now, I've only ever used the vanilla Javadocs. That would explain the markdown and odd tags I've never seen before.

High hopes this is fine now? Don't be afraid to let me know if there are any other issues.

SethFalco and others added 2 commits February 27, 2021 16:35
Co-authored-by: Ayaan Khan <ayaankhan98@gmail.com>
Copy link
Member

@ayaankhan98 ayaankhan98 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your contribution @SethFalco

@ayaankhan98 ayaankhan98 merged commit b4d104d into TheAlgorithms:master Feb 27, 2021
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.

2 participants