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.
I applied refactoring on 2 methods getRandomPoint, overlaps.
Extract Method: I applied extract method on getRandomPoint by extracting complex logic from the method and placing it into two smaller task specific methods. Below are the extracted methods:
i. randomizePointOnEllipse() This method is responsible for calculating a random point on an ellipse.
ii. randomizePointWithStroke() This method provides randomness based on the stroke width.
Decompose Conditional: I decomposed conditions in overlaps method and created three new methods to reduce conditional complexities in the method. Below are the newly created conditional methods:
i. checkOverlapWithRotation() This method checks for overlap between the current object (this) and another AbstractCanvasObject (that) considering the rotation.
ii. checkOverlapWithoutRotation() This method checks for overlap between the current object (this) and another CanvasObject (other) without considering rotation.
iii. checkContains() checks if the provided CanvasObject (obj) contains the specified Location (loc) using the contains method with a false flag.
Introduce explaining variable: I created a static explaining string variable named results which contains “result” as a value. This string literal was repeatedly used throughout the class without declaration and this can create refactoring process complex.
Also,
Refactored this three classes:
Extract Class: SvgReader class had multiple methods with unrelated responsibility. There were nine methods related to creating shapes and other six were related to getting properties of the components. I created new class PropertyReader for property related methods and kept shape related methods in SvgReader.
Replace conditional with polymorphism: In class SelectTool, the setMouse method contains a switch statement that performs different actions based on the value of curAction. This is a clear case of conditional logic that can be replaced with polymorphism. Refactoring this will make it more flexible to add new actions without modifying the setMouse method.
Move Method: The open and save methods in the HdlFile class were used only in the HdlContentEditor class. The open method reads a file and sets the text of the HdlContentEditor, while the save method writes the text of the HdlContentEditor to a file. It is more practical to move this methods to HdlContentEditor class because they are more related to the responsibility of this class.