...

Source file src/github.com/golang/geo/s2/edge_vector_shape_test.go

Documentation: github.com/golang/geo/s2

     1  // Copyright 2017 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  package s2
    16  
    17  // Shape interface enforcement
    18  var (
    19  	_ Shape = (*edgeVectorShape)(nil)
    20  )
    21  
    22  // edgeVectorShape is a Shape representing an arbitrary set of edges. It
    23  // is used for testing, but it can also be useful if you have, say, a
    24  // collection of polylines and don't care about memory efficiency (since
    25  // this type would store most of the vertices twice).
    26  type edgeVectorShape struct {
    27  	edges []Edge
    28  }
    29  
    30  // edgeVectorShapeFromPoints returns an edgeVectorShape of length 1 from the given points.
    31  func edgeVectorShapeFromPoints(a, b Point) *edgeVectorShape {
    32  	e := &edgeVectorShape{
    33  		edges: []Edge{
    34  			{a, b},
    35  		},
    36  	}
    37  	return e
    38  }
    39  
    40  // Add adds the given edge to the shape.
    41  func (e *edgeVectorShape) Add(a, b Point) {
    42  	e.edges = append(e.edges, Edge{a, b})
    43  }
    44  func (e *edgeVectorShape) NumEdges() int                          { return len(e.edges) }
    45  func (e *edgeVectorShape) Edge(id int) Edge                       { return e.edges[id] }
    46  func (e *edgeVectorShape) ReferencePoint() ReferencePoint         { return OriginReferencePoint(false) }
    47  func (e *edgeVectorShape) NumChains() int                         { return len(e.edges) }
    48  func (e *edgeVectorShape) Chain(chainID int) Chain                { return Chain{chainID, 1} }
    49  func (e *edgeVectorShape) ChainEdge(chainID, offset int) Edge     { return e.edges[chainID] }
    50  func (e *edgeVectorShape) ChainPosition(edgeID int) ChainPosition { return ChainPosition{edgeID, 0} }
    51  func (e *edgeVectorShape) IsEmpty() bool                          { return defaultShapeIsEmpty(e) }
    52  func (e *edgeVectorShape) IsFull() bool                           { return defaultShapeIsFull(e) }
    53  func (e *edgeVectorShape) Dimension() int                         { return 1 }
    54  func (e *edgeVectorShape) typeTag() typeTag                       { return typeTagNone }
    55  func (e *edgeVectorShape) privateInterface()                      {}
    56  

View as plain text