Skip to content

Add Barnsley Farn java implementation #830

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

Merged

Conversation

stormofice
Copy link
Contributor

No description provided.

@stormofice stormofice changed the title Adds Barnsley Farn java implementation Add Barnsley Farn java implementation Aug 20, 2021
return outputPoints;
}

public static Point matrixMultiplication(double[][] operation, double[] point) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java does not support matrix multiplication in its standard library, so this function was necessary.
Converting between Points and double Arrays is kind of unintuitive, but I think that Points being objects in general does make the code more readable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could integrate the matrix multiplication logic to the Point class and remove the conversions altogether?
That would probably also involve a second constructor taking a double[] (and checking the length is 3)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should either not do the conversion at the end and return a double[], or explicitly work with a Point and return a Point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided on keeping it consistent by using double arrays, because it is easier to work with them here.

However is checking for the array length in the constructor really necessary?
I do think that error handling would clutter up the algorithm a bit.

Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there, great PR overall, though I do have a few nitpicks I'd like you to address.

First off, the matrix multiplication code suspiciously lacks the loop braces. Although it's possible for single-line for loops, I don't recommend it for double for loops.

Second, I think the conversions between Point and double[] is inconsistent. Why do you want to return a Point from a double[] in the matrixMultiplication and not just do Point to Point?

Related to this, maybe adding a public Point(double[] array) could be useful for more direct conversions.

Finally, and not blocking as I'm not sure if we have a style guide decision for this, but I don't think we should teach the bad practice of letting main throw exceptions that can crash the program at any time with a potentially cryptic message.
I think we already merged Java implementations doing exactly this, so you don't have to modify that part here.

In any case, thanks for the PR :)

return outputPoints;
}

public static Point matrixMultiplication(double[][] operation, double[] point) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could integrate the matrix multiplication logic to the Point class and remove the conversions altogether?
That would probably also involve a second constructor taking a double[] (and checking the length is 3)

return outputPoints;
}

public static Point matrixMultiplication(double[][] operation, double[] point) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should either not do the conversion at the end and return a double[], or explicitly work with a Point and return a Point.

Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, you made your choices, and although I don't agree with all of them, it's still good code, so it has my approval.

Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem with that code.
We discussed the implementation of the matrix multiplication privately on Discord and @stormofice used the version I gave them, so I'm not sure whether I can review this version.

@Amaras Amaras added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Aug 21, 2021
@leios leios merged commit c1467a8 into algorithm-archivists:master Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants