Skip to content

Fixes #29 #30

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

AhmedHamdiy
Copy link

This pull request includes changes to the CTAlternateArray2D class to improve the iteration methods by making them more efficient and readable.

  • CTAlternateArray2D >> allPositionsDo:: Replaced the call to firstPosition pointTo: self dimension do: with nested loops iterating over the height and width, directly applying the block to each position.
  • CTAlternateArray2D >> allPositionsWithin:from:: Simplified the method by using ranges for x and y coordinates and collecting points within these ranges, instead of calculating top-left and bottom-right points and iterating over them.

@AhmedHamdiy
Copy link
Author

A more efficient solution was to add this method to the [Point] class in the [Kernel] package.

 pointTo: endPoint do: aBlock

    "Evaluate aBlock for each point from the receiver (start) to endPoint, inclusive, in row-major order."
    
    | startX startY endX endY |
    
    startX := self x.
        
    startY := self y.
        
    endX := endPoint x.
        
    endY := endPoint y.

    startY to: endY do: [ :yIndex |

        startX to: endX do: [ :xIndex |

            aBlock value: (xIndex @ yIndex)
        ]

    ]

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.

1 participant