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

Refactorings #8

Merged
merged 5 commits into from
Sep 1, 2024
Merged

Refactorings #8

merged 5 commits into from
Sep 1, 2024

Conversation

jolohaga
Copy link
Owner

@jolohaga jolohaga commented Aug 15, 2024

These are three commits:

  • Include segment endpoints (d4b5769)
  • Add validation (1f126e5)
  • Move to an instance implementation (5284cee)
  • New structure and implementation (50a0d9e)

Ancestors of given numbers should include the segment endpoints.

This change adds the segment endpoints to methods providing the ancestors of the
number.
We should guard that number arguments are within the range of the base segment
of the particular fraction tree. That is, that Farey tree numbers are within 0
and 1, octave reduced tree numbers are within 1 and 2, etc. Not doing so causes
run-away processes trying to find nodes for numbers outside of their tree's
range.

This commit adds a validate call to check a number is within the tree's base
segment, before executing some methods, like path_to.
Using classes to denote the types of fraction trees doesn't scale well. It
requires the user to know which class associates with which range of the tree,
and it doesn't support custom tree ranges easily.

All the former ability can be achieved using a class instance, and keywords to
denote the different known tree ranges. With one class, we can also expand the
constructor to accept keyword arguments, which lets us define custom tree
ranges more easily.

This change does the following:

1. Moves the behaviour of the various FractionTree sub-classes into the
   FractionTree class. This change also moves most formerly class methods to
   instance methods in the FractionTree class.
2. Fixes a bug in which a number whose value matches an endpoint, was causing
   #path_to to run-away. The method now includes a guard to return the endpoint
   when the value of number matches it.
3. Adds the #to_node method to the String class, to facilitate converting
   strings like "1/0" into FractionTree:Nodes.
These changes continue the re-organization and re-assignment of
responsibilities started in the previous commit.

Changes include:

* Introduce matrices to generate paths
* Move node related methods to instance methods in the Node class
* Add caching in the FractionTree class for faster lookups of nodes
* Avail a more flexible control of the fraction tree's range
* Add #to_node methods in Ruby primitive classes
* Add Stern-Brocot .encode and .decode methods
@jolohaga jolohaga merged commit e3e9a38 into main Sep 1, 2024
@jolohaga jolohaga deleted the refactorings branch September 1, 2024 05:27
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