-
- Notifications
You must be signed in to change notification settings - Fork 359
Jarvis March Implementation in Java #354
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
Jarvis March Implementation in Java #354
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't take this criticism too hard and please call me out on bullshit if I'm just wrong.
} | ||
} | ||
| ||
public static ArrayList<Integer[]> jarvisMarch(ArrayList<Integer[]> arr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda feel like this should be encapsulated in a private method named getLeftestPoint
, but you really only need it once so it's not like that will safe you much space. Discussion is open on this one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part of my code that finds the leftmost point is small, so I'll add a comment labeling it. In fact, I'll just go through and add more comments.
So it looks like this one was mostly reviewed by @Trashtalk217 , what is the current state of this PR @crafter312 ? |
I’m slowly doing work on it. Haven’t had much time though because i’m currently working on my college applications, but i’ll try finish my edits within the next couple weeks. I’ve been reading about the Vector2D library that @Trashtalk217 mentioned. Do you know if there is a good alternative using the default java libraries? |
No rush here! I was just checking in. Unfortunately, I don't know Java and using an external library might be useful in this case. I am not honestly sure the best way to progress there. |
@crafter312
I'm kinda on the fence on which to choose, which one do you prefer? |
I'm leaning towards creating my own smaller Vector2D class. If I did, would the best way be to make it a nested class so people can see it as part of the code example? |
I support the idea of using a nested class. I think it would be the best option to keep the code approachable and concise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the raw arrays is confusing and is not very readable, you should encapsulate the points in their own class as stated before, take a look at other implementations such as C++ or python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello and thank you for your 1st PR. I'll try to review this as good as I can.
Here are some general points:
- Indentation for Java files should be 4 spaces. You have 2.
if(p.getX()==x&&p.getY()== y)
should beif (p.getX() == x && p.getY() == y)
- braces on all conditions/loops
public double getY() { return y; } | ||
| ||
public boolean equals(Point p) { | ||
if(p.getX()==x&&p.getY()==y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have recently wrote Code style guide. In general is usage of spaces. So all places like if(p.getX()==x&&p.getY()==y)
should be if (p.getX() == x && p.getY() == y)
and also I have to ask you to add braces to this and all conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed my usage of spaces. Also, the editor I use for Java was configured to use two spaces for indentation, so I changed that to four.
{7, -7}, {-2, -9}, {6, -5}, {0, 14}, {2, 8}}; | ||
ArrayList<Integer[]> lst2 = new ArrayList<Integer[]>(Arrays.asList(lst)); | ||
ArrayList<Point> gift = new ArrayList<Point>(); | ||
for(Integer[] i: lst2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole part would be much more readable if you define just new ArrayList<Point>()
and add all points directly into that, instead of this transformation.
When you change it to creating points, you can remove constructor Point(Integer[] p)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, it looks much better.
When you change these 2 things, I think it can be merged afterwards.
} else {
to
} else {
and add new line on the end java file.
Great job and thank you for improving AAA! :) |
It works, but I could use some tips on how to improve it!