1 // Copyright 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 #include "s2/s2shapeutil_edge_iterator.h"
17 
18 #include "absl/strings/str_cat.h"
19 
20 namespace s2shapeutil {
21 
EdgeIterator(const S2ShapeIndex * index)22 EdgeIterator::EdgeIterator(const S2ShapeIndex* index)
23     : index_(index), shape_id_(-1), num_edges_(0), edge_id_(-1) {
24   Next();
25 }
26 
edge() const27 S2Shape::Edge EdgeIterator::edge() const {
28   S2_DCHECK(!Done());
29   return index_->shape(shape_id_)->edge(edge_id_);
30 }
31 
Next()32 void EdgeIterator::Next() {
33   while (++edge_id_ >= num_edges_) {
34     if (++shape_id_ >= index_->num_shape_ids()) break;
35     S2Shape* shape = index_->shape(shape_id_);
36     num_edges_ = (shape == nullptr) ? 0 : shape->num_edges();
37     edge_id_ = -1;
38   }
39 }
40 
DebugString() const41 std::string EdgeIterator::DebugString() const {
42   return absl::StrCat("(shape=", shape_id_, ", edge=", edge_id_, ")");
43 }
44 
45 }  // namespace s2shapeutil
46