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

Added Mirror Formulae Equation #9717

Merged
merged 13 commits into from
Oct 5, 2023
Merged

Added Mirror Formulae Equation #9717

merged 13 commits into from
Oct 5, 2023

Conversation

vipinkarthic
Copy link
Contributor

Describe your change:

This PR adds an algorithm involving the Mirror formulae for finding, the Focal Length, Object Distance from mirror, Image Distance form the mirror.

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

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 Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Oct 4, 2023
@cclauss
Copy link
Member

cclauss commented Oct 4, 2023

python3 -m doctest -v physics/mirror_formulae.py

=================================== FAILURES ===================================
________________ [doctest] physics.mirror_formulae.focal_length ________________
062
063 >>> focal_length(10, 20)
Expected:
6.666666666666667
Got:
6.666666666666666

/home/runner/work/Python/Python/physics/mirror_formulae.py:63: DocTestFailure
_______________ [doctest] physics.mirror_formulae.image_distance _______________
104
105 >>> image_distance(10, 40)
Expected:
13.33333333
Got:
8.0

/home/runner/work/Python/Python/physics/mirror_formulae.py:105: DocTestFailure
______________ [doctest] physics.mirror_formulae.object_distance _______________
083
084 >>> object_distance(30, 20)
Expected:
-60
Got:
-59.999999999999986

/home/runner/work/Python/Python/physics/mirror_formulae.py:84: DocTestFailure
=============================== warnings summary ===============================

@cclauss
Copy link
Member

cclauss commented Oct 4, 2023

You might need to use https://docs.python.org/3/library/math.html#math.isclose to make your doctests work on all platforms.

@vipinkarthic
Copy link
Contributor Author

You might need to use https://docs.python.org/3/library/math.html#math.isclose to make your doctests work on all platforms.

Hello !

Thanks for looking into my PR, but i am really confused on how to implement the math.isclose() function in this case since it returns a boolean value. I would be very grateful if you can help me with how to implement it.

In the meantime I did try using the round() function, since it gives a more simplified answer, would love to know if that's ok or I should change it to the math.isclose() function.

@cclauss
Copy link
Member

cclauss commented Oct 4, 2023

>>> from math import is_close
>>> is_close(focal_length(10, 20), 6.66666666666666)
True

@vipinkarthic
Copy link
Contributor Author

I will recheck where I'm going wrong and commit the changes soon.

Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

"""

<<<<<<< HEAD
=======

Choose a reason for hiding this comment

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

An error occurred while parsing the file: physics/mirror_formulae.py

Traceback (most recent call last):
  File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
    reports = lint_file(
              ^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 61:3.
parser error: error at 60:2: expected one of (, *, +, -, ..., AWAIT, EOF, False, NAME, NUMBER, None, True, [, break, continue, lambda, match, not, pass, ~

=======
  ^

@vipinkarthic
Copy link
Contributor Author

vipinkarthic commented Oct 5, 2023

I have resolved the issue, Please let me know if any more changes are to be made ! 😄

@@ -57,13 +57,13 @@

"""


from math import isclose
Copy link
Member

Choose a reason for hiding this comment

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

Please move this import into the doctest so that the linter does not get confused.

>>> isclose(object_distance(30, 20), -60.0)
True
>>> isclose(object_distance(10.5, 11.7), 102.375)
True
Copy link
Member

@cclauss cclauss Oct 5, 2023

Choose a reason for hiding this comment

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

I do not think we need is_close() here. Let’s only use it where we need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When running the doctests locally, there were issues when used without the isclose, should i still remove them or leave it as it is ?
image

image

Copy link
Member

Choose a reason for hiding this comment

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

Ok. We need is_close()

Copy link
Contributor Author

@vipinkarthic vipinkarthic Oct 5, 2023

Choose a reason for hiding this comment

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

Is there anything else I should add/change ?, or just have to wait till PR is merged ?

@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 5, 2023
@cclauss cclauss merged commit 935d1d3 into TheAlgorithms:master Oct 5, 2023
@cclauss
Copy link
Member

cclauss commented Oct 5, 2023

Nice one!!

@vipinkarthic
Copy link
Contributor Author

Thank You, I'm looking forward add more 😄

@cclauss
Copy link
Member

cclauss commented Oct 5, 2023

>>> from math import isclose
>>> isclose(focal_length(9.5, 6.7), 3.929012346)
True
>>> focal_length(0, 20)
Copy link
Member

Choose a reason for hiding this comment

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

>>> focal_length(0, 20)  # doctest: +NORMALIZE_WHITESPACE

>>> from math import isclose
>>> isclose(object_distance(10.5, 11.7), 102.375)
True
>>> object_distance(90, 0)
Copy link
Member

@cclauss cclauss Oct 5, 2023

Choose a reason for hiding this comment

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

# doctest: +NORMALIZE_WHITESPACE

>>> from math import isclose
>>> isclose(image_distance(1.5, 6.7), 1.932692308)
True
>>> image_distance(0, 0)
Copy link
Member

Choose a reason for hiding this comment

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

# doctest: +NORMALIZE_WHITESPACE

@cclauss
Copy link
Member

cclauss commented Oct 5, 2023

Can you please make a new PR with those three comments added so the build tests pass?

@vipinkarthic
Copy link
Contributor Author

Yes, I will do it right now

@vipinkarthic
Copy link
Contributor Author

I have created a added ( Normalize Whitespace ) and created the Pull request.
https://github.com/TheAlgorithms/Python/pull/9782

sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* Python mirror_formulae.py is added to the repository

* Changes done after reading readme.md

* Changes for running doctest on all platforms

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Change 2 for Doctests

* Changes for doctest 2

* updating DIRECTORY.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests are failing Do not merge until tests pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants