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