Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2287 | - | 1 | |
2 | namespace GMap.NET |
||
3 | { |
||
4 | using System.Globalization; |
||
5 | using System; |
||
6 | using System.Collections.Generic; |
||
7 | |||
8 | /// <summary> |
||
9 | /// the point ;} |
||
10 | /// </summary> |
||
11 | [Serializable] |
||
12 | public struct GPoint |
||
13 | { |
||
14 | public static readonly GPoint Empty = new GPoint(); |
||
15 | |||
16 | private long x; |
||
17 | private long y; |
||
18 | |||
19 | public GPoint(long x, long y) |
||
20 | { |
||
21 | this.x = x; |
||
22 | this.y = y; |
||
23 | } |
||
24 | |||
25 | public GPoint(GSize sz) |
||
26 | { |
||
27 | this.x = sz.Width; |
||
28 | this.y = sz.Height; |
||
29 | } |
||
30 | |||
31 | //public GPoint(int dw) |
||
32 | //{ |
||
33 | // this.x = (short) LOWORD(dw); |
||
34 | // this.y = (short) HIWORD(dw); |
||
35 | //} |
||
36 | |||
37 | public bool IsEmpty |
||
38 | { |
||
39 | get |
||
40 | { |
||
41 | return x == 0 && y == 0; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | public long X |
||
46 | { |
||
47 | get |
||
48 | { |
||
49 | return x; |
||
50 | } |
||
51 | set |
||
52 | { |
||
53 | x = value; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | public long Y |
||
58 | { |
||
59 | get |
||
60 | { |
||
61 | return y; |
||
62 | } |
||
63 | set |
||
64 | { |
||
65 | y = value; |
||
66 | } |
||
67 | } |
||
68 | |||
69 | public static explicit operator GSize(GPoint p) |
||
70 | { |
||
71 | return new GSize(p.X, p.Y); |
||
72 | } |
||
73 | |||
74 | public static GPoint operator+(GPoint pt, GSize sz) |
||
75 | { |
||
76 | return Add(pt, sz); |
||
77 | } |
||
78 | |||
79 | public static GPoint operator-(GPoint pt, GSize sz) |
||
80 | { |
||
81 | return Subtract(pt, sz); |
||
82 | } |
||
83 | |||
84 | public static bool operator==(GPoint left, GPoint right) |
||
85 | { |
||
86 | return left.X == right.X && left.Y == right.Y; |
||
87 | } |
||
88 | |||
89 | public static bool operator!=(GPoint left, GPoint right) |
||
90 | { |
||
91 | return !(left == right); |
||
92 | } |
||
93 | |||
94 | public static GPoint Add(GPoint pt, GSize sz) |
||
95 | { |
||
96 | return new GPoint(pt.X + sz.Width, pt.Y + sz.Height); |
||
97 | } |
||
98 | |||
99 | public static GPoint Subtract(GPoint pt, GSize sz) |
||
100 | { |
||
101 | return new GPoint(pt.X - sz.Width, pt.Y - sz.Height); |
||
102 | } |
||
103 | |||
104 | public override bool Equals(object obj) |
||
105 | { |
||
106 | if(!(obj is GPoint)) |
||
107 | return false; |
||
108 | GPoint comp = (GPoint) obj; |
||
109 | return comp.X == this.X && comp.Y == this.Y; |
||
110 | } |
||
111 | |||
112 | public override int GetHashCode() |
||
113 | { |
||
114 | return (int)(x ^ y); |
||
115 | } |
||
116 | |||
117 | public void Offset(long dx, long dy) |
||
118 | { |
||
119 | X += dx; |
||
120 | Y += dy; |
||
121 | } |
||
122 | |||
123 | public void Offset(GPoint p) |
||
124 | { |
||
125 | Offset(p.X, p.Y); |
||
126 | } |
||
127 | public void OffsetNegative(GPoint p) |
||
128 | { |
||
129 | Offset(-p.X, -p.Y); |
||
130 | } |
||
131 | |||
132 | public override string ToString() |
||
133 | { |
||
134 | return "{X=" + X.ToString(CultureInfo.CurrentCulture) + ",Y=" + Y.ToString(CultureInfo.CurrentCulture) + "}"; |
||
135 | } |
||
136 | |||
137 | //private static int HIWORD(int n) |
||
138 | //{ |
||
139 | // return (n >> 16) & 0xffff; |
||
140 | //} |
||
141 | |||
142 | //private static int LOWORD(int n) |
||
143 | //{ |
||
144 | // return n & 0xffff; |
||
145 | //} |
||
146 | } |
||
147 | |||
148 | internal class GPointComparer : IEqualityComparer<GPoint> |
||
149 | { |
||
150 | public bool Equals(GPoint x, GPoint y) |
||
151 | { |
||
152 | return x.X == y.X && x.Y == y.Y; |
||
153 | } |
||
154 | |||
155 | public int GetHashCode(GPoint obj) |
||
156 | { |
||
157 | return obj.GetHashCode(); |
||
158 | } |
||
159 | } |
||
160 | } |