Repository navigation
[R45-T016] Simplify pixel-to-figure coordinate mapping in Mandelbrot - #56
Open
shyamlibakale1001-alt wants to merge 1 commit into
Open
shyamlibakale1001-alt wants to merge 1 commit into
shyamlibakale1001-alt wants to merge 1 commit into
Conversation
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.
Description
Extracts the duplicated pixel-to-figure-space coordinate transformation in
Mandelbrot.getImageinto a named helperpixelToFigureCoordinate(int, int, double, double)insrc/main/java/com/thealgorithms/others/Mandelbrot.java, adds JUnit regression tests (MandelbrotTest.java) locking down the source anchors and independently calculated neighboring inputs, and adds a focused runner (work/R45-T016/check.py). All behavior, return types, ordering, side effects, and public arguments are preserved.Related Issue
Fixes: #16
Type of Change
Changes Made
pixelToFigureCoordinate(int pixelIndex, int imageSpan, double figureCenter, double figureSpan)insrc/main/java/com/thealgorithms/others/Mandelbrot.java(lines 107–118), replacing the duplicated inline formula forfigureXandfigureYinsidegetImage(...)(lines 94–95). Arithmetic order is identical, so floating-point results are unchanged.src/test/java/com/thealgorithms/others/MandelbrotTest.javawith 3 test methods (13 logged assertions):Mandelbrot.main(blackAndWhiteImage.getRGB(0, 0),blackAndWhiteImage.getRGB(400, 300),coloredImage.getRGB(0, 0),coloredImage.getRGB(400, 300)) plus neighboring pixel(1, 0)on both images.2×2grid (getImage(2, 2, 0.0, 0.0, 2.0, 5, false/true)) verifying(0, 0)→distance = 0.25→Color(127, 255, 0)(colored) / white (B&W),(0, 1)period-2 boundary → black, and(1, 1)fixed point → black.imageWidth <= 0,imageHeight <= 0,maxStep <= 0throwingIllegalArgumentExceptionwith exact messages).work/R45-T016/check.py(with evidence files inwork/R45-T016/), runningmvn testforMandelbrotTest, enforcing a nonzero test count, savingcomparisons.txt,result.txt,mvn_output.txt, andtool_versions.txt, and exiting non-zero on failure.Screenshots / Recordings
Not applicable (no UI changes).
Testing
Command:
python3 work/R45-T016/check.py(runs
mvn -B test -Dtest=MandelbrotTest -Dsurefire.failIfNoSpecifiedTests=false)Before refactor:
tests=3 failures/errors=0 skipped=0 records=13 mvn_exit=0,status=PASSAfter refactor:
tests=3 failures/errors=0 skipped=0 records=13 mvn_exit=0,status=PASSNegative check: temporarily changing
- 0.5to+ 0.5inpixelToFigureCoordinateon line 117 causedpython3 work/R45-T016/check.pyto printstatus=FAIL(tests=3 failures/errors=2 skipped=0 mvn_exit=1) and exit non-zero; reverted and re-verified.Style:
mvn -B checkstyle:checkreports0 Checkstyle violations(BUILD SUCCESS).Tool versions and check records are saved in
work/R45-T016/tool_versions.txtandwork/R45-T016/comparisons.txt.Checklist
Additional Notes
Operation made clearer: pixel-to-figure-space axis coordinate mapping (
pixelToFigureCoordinate), eliminating the duplicated X/Y axis expression insidegetImage.The
work/R45-T016/evidence folder is for coursework review only and should not go into any later upstream PR.I have read CONTRIBUTING.md.
This pull request is all my own work -- I have not plagiarized it.
All filenames are in PascalCase.
All functions and variable names follow Java naming conventions.
All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
All new algorithms include a corresponding test class that validates their functionality.
All new code is formatted with
clang-format -i --style=file path/to/your/file.java