...

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

Documentation: github.com/golang/geo/s2

     1  // Copyright 2023 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  const laxPolylineTypeTag = 4
    18  
    19  // LaxPolyline represents a polyline. It is similar to Polyline except
    20  // that adjacent vertices are allowed to be identical or antipodal, and
    21  // the representation is slightly more compact.
    22  //
    23  // Polylines may have any number of vertices, but note that polylines with
    24  // fewer than 2 vertices do not define any edges. (To create a polyline
    25  // consisting of a single degenerate edge, either repeat the same vertex twice
    26  // or use LaxClosedPolyline.
    27  type LaxPolyline struct {
    28  	vertices []Point
    29  }
    30  
    31  // LaxPolylineFromPoints constructs a LaxPolyline from the given points.
    32  func LaxPolylineFromPoints(vertices []Point) *LaxPolyline {
    33  	return &LaxPolyline{
    34  		vertices: append([]Point(nil), vertices...),
    35  	}
    36  }
    37  
    38  // LaxPolylineFromPolyline converts the given Polyline into a LaxPolyline.
    39  func LaxPolylineFromPolyline(p Polyline) *LaxPolyline {
    40  	return LaxPolylineFromPoints(p)
    41  }
    42  
    43  func (l *LaxPolyline) NumEdges() int                     { return maxInt(0, len(l.vertices)-1) }
    44  func (l *LaxPolyline) Edge(e int) Edge                   { return Edge{l.vertices[e], l.vertices[e+1]} }
    45  func (l *LaxPolyline) ReferencePoint() ReferencePoint    { return OriginReferencePoint(false) }
    46  func (l *LaxPolyline) NumChains() int                    { return minInt(1, l.NumEdges()) }
    47  func (l *LaxPolyline) Chain(i int) Chain                 { return Chain{0, l.NumEdges()} }
    48  func (l *LaxPolyline) ChainEdge(i, j int) Edge           { return Edge{l.vertices[j], l.vertices[j+1]} }
    49  func (l *LaxPolyline) ChainPosition(e int) ChainPosition { return ChainPosition{0, e} }
    50  func (l *LaxPolyline) Dimension() int                    { return 1 }
    51  func (l *LaxPolyline) IsEmpty() bool                     { return defaultShapeIsEmpty(l) }
    52  func (l *LaxPolyline) IsFull() bool                      { return defaultShapeIsFull(l) }
    53  func (l *LaxPolyline) typeTag() typeTag                  { return typeTagLaxPolyline }
    54  func (l *LaxPolyline) privateInterface()                 {}
    55  
    56  // TODO(roberts):
    57  // Add Encode/Decode support
    58  // Add EncodedLaxPolyline type
    59  

View as plain text