-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImPoint.java
76 lines (60 loc) · 1.43 KB
/
ImPoint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* ImPoint Immutable Point class.
*
* author: CMB
*
* Mostly packages together an (x,y) coordinate pair into one object.
* Also includes conversion to java.awt.Point2D for use with the
* graphics system.
*
*/
import java.awt.geom.Point2D;
class ImPoint {
/**
Creates the point with coordinates (x,y)
*/
public ImPoint(int x, int y) {
this.x = x;
this.y = y;
}
/**
Returns an ImPoint with coordinates translated by deltaX
and deltaY from this point.
*/
public ImPoint translate(int deltaX, int deltaY) {
return new ImPoint(x + deltaX, y + deltaY);
}
/**
Returns a String version of the Point for debugging purposes.
In Java toString is a special function. You are allowed to do
a call like the following, and toString will get automatically
called to do the conversion:
ImPoint myImPoint . . .;
. . .
System.out.println(myImPoint);
*/
public String toString() {
return "ImPoint[" + x + "," + y + "]";
}
/*
* Retursn a Point2D with same coordinates as this point
*
*/
public Point2D getPoint2D() {
return new Point2D.Double(x, y);
}
/*
* Returns the x-coordinate of the point.
*/
public int getX() {
return x;
}
/*
* Returns the y-coordinate of the point.
*/
public int getY() {
return y;
}
private int x;
private int y;
}