1 module hunt.database.driver.postgresql.data.Circle;
2 
3 import hunt.database.driver.postgresql.data.Point;
4 
5 /**
6  * Circle data type in Postgres represented by a center {@link Point} and radius.
7  */
8 class Circle {
9     private Point centerPoint;
10     private double radius;
11 
12     this() {
13         this(new Point(), 0.0);
14     }
15 
16     this(Point centerPoint, double radius) {
17         this.centerPoint = centerPoint;
18         this.radius = radius;
19     }
20 
21     // this(JsonObject json) {
22     //     CircleConverter.fromJson(json, this);
23     // }
24 
25     Point getCenterPoint() {
26         return centerPoint;
27     }
28 
29     void setCenterPoint(Point centerPoint) {
30         this.centerPoint = centerPoint;
31     }
32 
33     double getRadius() {
34         return radius;
35     }
36 
37     void setRadius(double radius) {
38         this.radius = radius;
39     }
40 
41     override
42     bool opEquals(Object o) {
43         if (this is o) return true;
44 
45         Circle that = cast(Circle) o;
46         if(that is null) return false;
47 
48         if (radius != that.radius) return false;
49         if (centerPoint != that.centerPoint) return false;
50 
51         return true;
52     }
53 
54     override
55     size_t toHash() @trusted nothrow {
56         import hunt.Double;
57         size_t result = centerPoint.toHash();
58         ulong temp = Double.doubleToLongBits(radius);
59         result = 31 * result + cast(size_t) (temp ^ (temp >>> 32));
60         return result;
61     }
62 
63     override
64     string toString() {
65         import std.conv;
66         return "Circle<" ~ centerPoint.toString() ~ "," ~ radius.to!string() ~ ">";
67     }
68 
69     // JsonObject toJson() {
70     //     JsonObject json = new JsonObject();
71     //     CircleConverter.toJson(this, json);
72     //     return json;
73     // }
74 }