1 module hunt.database.driver.postgresql.data.Box;
2 
3 import hunt.database.driver.postgresql.data.Point;
4 
5 /**
6  * Rectangular box data type in Postgres represented by pairs of {@link Point}s that are opposite corners of the box.
7  */
8 class Box {
9     private Point upperRightCorner, lowerLeftCorner;
10 
11     this() {
12         this(new Point(), new Point());
13     }
14 
15     this(Point upperRightCorner, Point lowerLeftCorner) {
16         this.upperRightCorner = upperRightCorner;
17         this.lowerLeftCorner = lowerLeftCorner;
18     }
19 
20     // this(JsonObject json) {
21     //     BoxConverter.fromJson(json, this);
22     // }
23 
24     Point getUpperRightCorner() {
25         return upperRightCorner;
26     }
27 
28     void setUpperRightCorner(Point upperRightCorner) {
29         this.upperRightCorner = upperRightCorner;
30     }
31 
32     Point getLowerLeftCorner() {
33         return lowerLeftCorner;
34     }
35 
36     void setLowerLeftCorner(Point lowerLeftCorner) {
37         this.lowerLeftCorner = lowerLeftCorner;
38     }
39 
40     override bool opEquals(Object o) {
41         if (this is o)
42             return true;
43         if (o is null)
44             return false;
45 
46         Box box = cast(Box) o;
47         if (box is null)
48             return false;
49 
50         if (upperRightCorner != box.upperRightCorner)
51             return false;
52         if (lowerLeftCorner != box.lowerLeftCorner)
53             return false;
54 
55         return true;
56     }
57 
58     override size_t toHash() @trusted nothrow {
59         size_t result = upperRightCorner.toHash();
60         result = 31 * result + lowerLeftCorner.toHash();
61         return result;
62     }
63 
64     override string toString() {
65         return "Box(" ~ upperRightCorner.toString() ~ "," ~ lowerLeftCorner.toString() ~ ")";
66     }
67 
68     // JsonObject toJson() {
69     //     JsonObject json = new JsonObject();
70     //     BoxConverter.toJson(this, json);
71     //     return json;
72     // }
73 }