...

Source file src/github.com/golang/geo/s2/lax_polyline_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  // laxPolyline represents a polyline. It is similar to Polyline except
    18  // that duplicate vertices are allowed, and the representation is slightly
    19  // more compact.
    20  //
    21  // Polylines may have any number of vertices, but note that polylines with
    22  // fewer than 2 vertices do not define any edges. (To create a polyline
    23  // consisting of a single degenerate edge, either repeat the same vertex twice
    24  // or use laxClosedPolyline.
    25  type laxPolyline struct {
    26  	vertices []Point
    27  }
    28  
    29  func laxPolylineFromPoints(vertices []Point) *laxPolyline {
    30  	return &laxPolyline{
    31  		vertices: append([]Point(nil), vertices...),
    32  	}
    33  }
    34  
    35  func laxPolylineFromPolyline(p Polyline) *laxPolyline {
    36  	return laxPolylineFromPoints(p)
    37  }
    38  
    39  func (l *laxPolyline) NumEdges() int                     { return maxInt(0, len(l.vertices)-1) }
    40  func (l *laxPolyline) Edge(e int) Edge                   { return Edge{l.vertices[e], l.vertices[e+1]} }
    41  func (l *laxPolyline) ReferencePoint() ReferencePoint    { return OriginReferencePoint(false) }
    42  func (l *laxPolyline) NumChains() int                    { return minInt(1, l.NumEdges()) }
    43  func (l *laxPolyline) Chain(i int) Chain                 { return Chain{0, l.NumEdges()} }
    44  func (l *laxPolyline) ChainEdge(i, j int) Edge           { return Edge{l.vertices[j], l.vertices[j+1]} }
    45  func (l *laxPolyline) ChainPosition(e int) ChainPosition { return ChainPosition{0, e} }
    46  func (l *laxPolyline) Dimension() int                    { return 1 }
    47  func (l *laxPolyline) IsEmpty() bool                     { return defaultShapeIsEmpty(l) }
    48  func (l *laxPolyline) IsFull() bool                      { return defaultShapeIsFull(l) }
    49  func (l *laxPolyline) typeTag() typeTag                  { return typeTagLaxPolyline }
    50  func (l *laxPolyline) privateInterface()                 {}
    51  

View as plain text