1 // Copyright 2013 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 
16 // Original Author: ericv@google.com (Eric Veach)
17 // Converted to D:  madric@gmail.com (Vijay Nayar)
18 
19 module s2.s2point_vector_shape;
20 
21 import s2.s2shape;
22 import s2.s2point;
23 
24 // S2PointVectorShape is an S2Shape representing a set of S2Points. Each point
25 // is reprsented as a degenerate edge with the same starting and ending
26 // vertices.
27 //
28 // This class is useful for adding a collection of points to an S2ShapeIndex.
29 class S2PointVectorShape : S2Shape {
30 public:
31   // Constructs an empty point vector.
32   this() {}
33 
34   // Constructs an S2PointVectorShape from a vector of points.
35   this(S2Point[] points) {
36     _points = points;
37   }
38 
39   int numPoints() const {
40     return cast(int)(_points.length);
41   }
42 
43   S2Point point(int i) const {
44     return _points[i];
45   }
46 
47   // S2Shape interface:
48   final override
49   int numEdges() const {
50     return cast(int)(_points.length);
51   }
52 
53   final override
54   Edge edge(int e) const {
55     return Edge(_points[e], _points[e]);
56   }
57 
58   final override
59   int dimension() const {
60     return 0;
61   }
62 
63   final override
64   ReferencePoint getReferencePoint() const {
65     return ReferencePoint(false);
66   }
67 
68   final override
69   int numChains() const {
70     return cast(int)(_points.length);
71   }
72 
73   final override
74   Chain chain(int i) const {
75     return Chain(i, 1);
76   }
77 
78   final override
79   Edge chainEdge(int i, int j) const
80   in {
81     assert(j == 0);
82   } do {
83     return Edge(_points[i], _points[i]);
84   }
85 
86   final override
87   ChainPosition chainPosition(int e) const {
88     return ChainPosition(e, 0);
89   }
90 
91 private:
92   S2Point[] _points;
93 }