Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Help! Refactor the ProcessingImage class and modify the methods from the Util class so that it can test when the Rectangle intersect the point.

Java Help! Refactor the ProcessingImage class and modify the methods from the Util class so that it can test when the Rectangle intersect the point. Below are all the classes given.

I have 6 files, please follow all commented instructions

Only two files that need to be changed are ProcessingImage.java and Util.java (instructions in the comments)

/////////////////////////////////////////////////////////////////

ColorRGB.java

public class ColorRGB { public int R; public int G; public int B; public ColorRGB(int r, int g, int b) { R=r; G=g; B=b; } } 

////////////////////////////////////////////////////////

Line.java

/* a Line represents a line between 2 points (p1 and p2) Every line has an identifier and a color. */ public class Line { public String id; public Point2D p1; public Point2D p2; public ColorRGB col; public Line(Point2D p1, Point2D p2, String id, ColorRGB col) { this.p1=p1; this.p2=p2; this.id=id; this.col=col; } } 

////////////////////////////////////////////

Point2D.java

final class Point2D { public int x; public int y; public ColorRGB col = new ColorRGB(255,255,255); public Point2D(int x, int y) { this.x = x; this.y = y; } } 

//////////////////////////////////////////////////////////////////////

ProcessImge.java

import processing.core.PApplet; public class ProcessImage extends PApplet { public void settings() { size(500, 500); } private boolean redraw=false; private boolean start= true; public void setup() { background(180); //noLoop(); } public void draw() { if (start) { textSize(20); text("Click me!", 10, 30); fill(0, 102, 153); text("Now!", 10, 60); fill(0, 102, 153, 51); start= false; } if(redraw) { background(180);//reset background to gray // //you can comment the next 3 lines out after you are done! textSize(18); fill(0, 102, 153, 255); text("Read the instructions found in the code base!", 10, 90); //this will create a red line 10 pixel under the mouseclick ColorRGB red = new ColorRGB(255,0,0); stroke(red.R,red.B,red.G); line(mouseX,mouseY+10,mouseX+100,mouseY+10); //this will create a green rectangle stroke(0,255,0); fill(0,255,0); rect(100, 250, 100, 50); //this will create a blue dot at the place you clicked // for better visualization you can make this spot several pixels large stroke(0,0,255); point(mouseX,mouseY); redraw = false; } } public void mousePressed() { redraw= true; } public static void main(String args[]) { PApplet.main("ProcessImage"); //Modify this part so that it works after you refractored the code Point2D point = new Point2D(-3, 2); Rectangle blob1 = new Rectangle(new Point2D(-1, -1), new Point2D(1, 2), "blob1",new ColorRGB(255,0,0)); Rectangle blob2 = new Rectangle(new Point2D(0, 0), new Point2D(5, 1), "blob2",new ColorRGB(0,255,0)); Line edge = new Line(new Point2D(1,1), new Point2D(3, -1), "edge1",new ColorRGB(255,255,255)); boolean intersect; System.out.print(blob1.id + " intersected "); intersect = Util.testIntersect(blob1, blob2); System.out.println(blob2.id + ":" + intersect); intersect = Util.testIntersect(blob1, edge); System.out.println(edge.id + ":" + intersect); intersect = Util.testIntersect(blob1, point); System.out.println(point + ":" + intersect); } } 

//////////////////////////////////////////////////////

Rectangle.java

/* a Rectangle represents a rectangle which is given by two points (min and max) which can be seen as the two corners of the rectangle that define its shape. upper right corner =min lower left corner = max (Note that the coordinate system used runs horizontally in x direction from left to right and vertically in y direction from up to down.) Every Rectangle also has an identifier String and a color. */ public class Rectangle { public Point2D min; public Point2D max; public String id; public ColorRGB col; public Rectangle(Point2D min, Point2D max, String id, ColorRGB col){ this.min=min; this.max=max; this.id=id; this.col=col; } } 

///////////////////////////////////////////////////////////

Util.java (where most of the work needs to be done)

public class Util { public static boolean testIntersect(Rectangle blob1, Rectangle blob2) { //Provide code here after refactoring your code //If there is an intersection, both rectangles should turn red return false; } public static boolean testIntersect(Rectangle blob, Point2D p) { //Provide code here after refactoring your code //If there is an intersection, the rectangle should turn red and the point should grow in size (however large you want but so that the entire point is within the rectangle) return false; } public static boolean testIntersect(Rectangle blob, Line l) { //Provide code here after refactoring your code //If there is an intersection, the rectangles should turn red and the line should change it's color continuously from white to any color of your choice within a time scale so that this transition is visible. return false; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions