source: trunk/src/org/expeditee/core/Dimension.java@ 1097

Last change on this file since 1097 was 1097, checked in by davidb, 6 years ago

Newly structured files from Corey's work on logic/graphics separation

File size: 1.4 KB
Line 
1package org.expeditee.core;
2
3/**
4 * A Dimension represents the 2-dimensional size of something.
5 *
6 * @author cts16
7 */
8public class Dimension {
9
10 /** The size in the x-dimension. */
11 public int width;
12 /** The size in the y-dimension. */
13 public int height;
14
15 /** Defaults to a zero-area (degenerate) size if no arguments are given. */
16 public Dimension()
17 {
18 this(0, 0);
19 }
20
21 /** Standard constructor. */
22 public Dimension(int width, int height)
23 {
24 this.width = width;
25 this.height = height;
26 }
27
28 /** Copy constructor. */
29 public Dimension(Dimension other)
30 {
31 if (other != null) {
32 this.width = other.width;
33 this.height = other.height;
34 } else {
35 this.width = 0;
36 this.height = 0;
37 }
38 }
39
40 /** Gets the width of this dimension. */
41 public int getWidth()
42 {
43 return width;
44 }
45
46 /** Gets the height of this dimension. */
47 public int getHeight()
48 {
49 return height;
50 }
51
52 /** Gets the rectangular area of this dimension. */
53 public int getArea()
54 {
55 return width * height;
56 }
57
58 /** Sets any negative widths/heights to the absolute equivalents. */
59 public void absolve()
60 {
61 if (width < 0) width = -width;
62 if (height <0) height = -height;
63 }
64
65 @Override
66 public boolean equals(Object other)
67 {
68 if (other instanceof Dimension) {
69 Dimension d = (Dimension) other;
70 return this.width == d.width && this.height == d.height;
71 }
72
73 return false;
74 }
75
76 public Dimension clone()
77 {
78 return new Dimension(this);
79 }
80}
Note: See TracBrowser for help on using the repository browser.