Skip to content

[R45-T016] Simplify pixel-to-figure coordinate mapping in Mandelbrot - #56

Open
shyamlibakale1001-alt wants to merge 1 commit into
S-AI-Projects:masterfrom
shyamlibakale1001-alt:student/e26b07f0813/R45-T016
Open

shyamlibakale1001-alt wants to merge 1 commit into
S-AI-Projects:masterfrom
shyamlibakale1001-alt:student/e26b07f0813/R45-T016

Conversation

@shyamlibakale1001-alt

Copy link
Copy Markdown

Description

Extracts the duplicated pixel-to-figure-space coordinate transformation in Mandelbrot.getImage into a named helper pixelToFigureCoordinate(int, int, double, double) in src/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

  • Bug Fix
  • New Feature
  • UI/UX Improvement
  • Performance Improvement
  • Tests
  • Documentation
  • Refactoring / Maintenance
  • CI/CD

Changes Made

  • Extracted pixelToFigureCoordinate(int pixelIndex, int imageSpan, double figureCenter, double figureSpan) in src/main/java/com/thealgorithms/others/Mandelbrot.java (lines 107–118), replacing the duplicated inline formula for figureX and figureY inside getImage(...) (lines 94–95). Arithmetic order is identical, so floating-point results are unchanged.
  • Added src/test/java/com/thealgorithms/others/MandelbrotTest.java with 3 test methods (13 logged assertions):
    • Source anchors from 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.
    • Independently hand-calculated 2×2 grid (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.
    • Validation contract (imageWidth <= 0, imageHeight <= 0, maxStep <= 0 throwing IllegalArgumentException with exact messages).
  • Added work/R45-T016/check.py (with evidence files in work/R45-T016/), running mvn test for MandelbrotTest, enforcing a nonzero test count, saving comparisons.txt, result.txt, mvn_output.txt, and tool_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=PASS
After refactor: tests=3 failures/errors=0 skipped=0 records=13 mvn_exit=0, status=PASS

Negative check: temporarily changing - 0.5 to + 0.5 in pixelToFigureCoordinate on line 117 caused python3 work/R45-T016/check.py to print status=FAIL (tests=3 failures/errors=2 skipped=0 mvn_exit=1) and exit non-zero; reverted and re-verified.

Style: mvn -B checkstyle:check reports 0 Checkstyle violations (BUILD SUCCESS).

Tool versions and check records are saved in work/R45-T016/tool_versions.txt and work/R45-T016/comparisons.txt.

Checklist

  • I have tested my changes locally.
  • I have added or updated tests, if needed.
  • I have updated documentation, if needed.
  • I have followed the project's coding guidelines.
  • I have run the relevant tests and checks.
  • I have addressed previous review feedback, if applicable.

Additional Notes

  • Operation made clearer: pixel-to-figure-space axis coordinate mapping (pixelToFigureCoordinate), eliminating the duplicated X/Y axis expression inside getImage.

  • 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

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.

Shyamli Bakale — R45-T016: Simplify one responsibility in Mandelbrot (Mandelbrot.java) [src/main/java/com/thealgorithms/others/Mandelbrot.java]

1 participant