1 /**
2   2D line segment type.
3 
4   Copyright: Chris Jones
5   License: Boost Software License, Version 1.0
6   Authors: Chris Jones
7 */
8 
9 module dg2d.line;
10 
11 import dg2d.scalar;
12 import dg2d.point;
13 import dg2d.misc;
14 
15 //import std.algorithm: among;
16 
17 /**
18   2D line segment
19 */
20 
21 struct Line
22 {
23     Scalar x0 = 0;
24     Scalar y0 = 0;
25     Scalar x1 = 0;
26     Scalar y1 = 0;
27 
28     this(Scalar x0, Scalar y0, Scalar x1, Scalar y1)
29     {
30         this.x0 = x0;
31         this.y0 = y0;
32         this.x1 = x1;
33         this.y1 = y1;
34     }
35 
36     Scalar dx()
37     {
38         return x1-x0;
39     }
40     
41     Scalar dy()
42     {
43         return y1-y0;
44     }
45 
46     Scalar length()
47     {
48         return sqrt(sqr(dx)+sqr(dy));
49     }
50 
51     Point midPoint()
52     {
53         return Point((x0+x1)/2,(y0+y1)/2);
54     }
55 }