Question
java flip methods I need help debugging. The assignment: This method should copy the whole parameter Picture into the calling object, starting at position (startX,
java flip methods
I need help debugging.
The assignment:
This method should copy the whole parameter Picture into the calling object, starting at position (startX, startY) in the calling object. See the diagram below. Note that the black line in the flipped pictures just shows where the boundary of the copied in part is or would be, and is not actually part of the image.
Important notes and hints:
You should not assume that the calling object will be large enough to hold the image passed in in the location specified. If the image to be copied will go out of bounds, simply copy in the part that will fit in the specified position, and ignore the rest.
You may assume that startX and startY will be within the bounds of the calling object.
Your methods should not modify the parameter image. I.e. the image you pass in should be unchanged after the method is called. However, it is acceptable to create a new Picture within the method and modify that newly created Picture object as an intermediate step. You do not have to do this, though.
My code:
https://gist.github.com/Camicam311/36978fc2e625c27c6755e7b7c6e147b1
public void flipHorizontalInto(Picture source, int startX, int startY) { Color tempColor = null; Pixel sourcePixel = null; Pixel targetPixel = null;
for (int sx = startX, tx = startX + source.getWidth() - 1; sx startX + source.getWidth() - 1; sx++, tx--) { for (int sy = startY; sy
public void flipVerticalInto(Picture source, int startX, int startY) { Color tempColor = null; Pixel sourcePixel = null; Pixel targetPixel = null;
for (int sx = startX; sx startY + this.getHeight() - 1; sy++, ty--) { sourcePixel = source.getPixel(sx, sy); tempColor = sourcePixel.getColor(); targetPixel = source.getPixel(sx, ty); sourcePixel.setColor(targetPixel.getColor()); targetPixel.setColor(tempColor); } } }
The testers fail saying the source image was not copied correctly.
canvas source canvas.flipVe rticalInto (source, 2, 5); canvas.flipH 5)canvas.flipHorizontalInto (source, 5, 5); canvas canvasStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started