...

Source file src/github.com/golang/geo/s2/lax_polyline_test_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  import (
    18  	"testing"
    19  )
    20  
    21  func TestLaxPolylineNoVertices(t *testing.T) {
    22  	shape := Shape(LaxPolylineFromPoints([]Point{}))
    23  
    24  	if got, want := shape.NumEdges(), 0; got != want {
    25  		t.Errorf("shape.NumEdges() = %v, want %v", got, want)
    26  	}
    27  	if got, want := shape.NumChains(), 0; got != want {
    28  		t.Errorf("shape.NumChains() = %v, want %v", got, want)
    29  	}
    30  	if got, want := shape.Dimension(), 1; got != want {
    31  		t.Errorf("shape.Dimension() = %v, want %v", got, want)
    32  	}
    33  	if !shape.IsEmpty() {
    34  		t.Errorf("shape.IsEmpty() = false, want true")
    35  	}
    36  	if shape.IsFull() {
    37  		t.Errorf("shape.IsFull() = true, want false")
    38  	}
    39  	if shape.ReferencePoint().Contained {
    40  		t.Errorf("shape.ReferencePoint().Contained = true, want false")
    41  	}
    42  }
    43  
    44  func TestLaxPolylineOneVertex(t *testing.T) {
    45  	shape := Shape(LaxPolylineFromPoints([]Point{PointFromCoords(1, 0, 0)}))
    46  	if got, want := shape.NumEdges(), 0; got != want {
    47  		t.Errorf("shape.NumEdges() = %v, want %v", got, want)
    48  	}
    49  	if got, want := shape.NumChains(), 0; got != want {
    50  		t.Errorf("shape.NumChains() = %v, want %v", got, want)
    51  	}
    52  	if got, want := shape.Dimension(), 1; got != want {
    53  		t.Errorf("shape.Dimension() = %v, want %v", got, want)
    54  	}
    55  	if !shape.IsEmpty() {
    56  		t.Errorf("shape.IsEmpty() = false, want true")
    57  	}
    58  	if shape.IsFull() {
    59  		t.Errorf("shape.IsFull() = true, want false")
    60  	}
    61  }
    62  
    63  func TestLaxPolylineEdgeAccess(t *testing.T) {
    64  	vertices := parsePoints("0:0, 0:1, 1:1")
    65  	shape := Shape(LaxPolylineFromPoints(vertices))
    66  
    67  	if got, want := shape.NumEdges(), 2; got != want {
    68  		t.Errorf("shape.NumEdges() = %v, want %v", got, want)
    69  	}
    70  	if got, want := shape.NumChains(), 1; got != want {
    71  		t.Errorf("shape.NumChains() = %v, want %v", got, want)
    72  	}
    73  	if got, want := shape.Chain(0).Start, 0; got != want {
    74  		t.Errorf("shape.Chain(%d).Start = %d, want 0", got, want)
    75  	}
    76  	if got, want := shape.Chain(0).Length, 2; got != want {
    77  		t.Errorf("shape.Chain(%d).Length = %d, want 2", got, want)
    78  	}
    79  	if got, want := shape.Dimension(), 1; got != want {
    80  		t.Errorf("shape.Dimension() = %v, want %v", got, want)
    81  	}
    82  	if shape.IsEmpty() {
    83  		t.Errorf("shape.IsEmpty() = true, want false")
    84  	}
    85  	if shape.IsFull() {
    86  		t.Errorf("shape.IsFull() = true, want false")
    87  	}
    88  
    89  	edge0 := shape.Edge(0)
    90  	if !edge0.V0.ApproxEqual(vertices[0]) {
    91  		t.Errorf("shape.Edge(0).V0 = %v, want %v", edge0.V0, vertices[0])
    92  	}
    93  	if !edge0.V1.ApproxEqual(vertices[1]) {
    94  		t.Errorf("shape.Edge(0).V1 = %v, want %v", edge0.V1, vertices[1])
    95  	}
    96  
    97  	edge1 := shape.Edge(1)
    98  	if !edge1.V0.ApproxEqual(vertices[1]) {
    99  		t.Errorf("shape.Edge(1).V0 = %v, want %v", edge1.V0, vertices[1])
   100  	}
   101  	if !edge1.V1.ApproxEqual(vertices[2]) {
   102  		t.Errorf("shape.Edge(1).V1 = %v, want %v", edge1.V1, vertices[2])
   103  	}
   104  }
   105  
   106  // TODO(roberts): Remaining tests to complete:
   107  // RoundtripEncoding
   108  // CoderWorks
   109  // ChainIteratorWorks
   110  // ChainVertexIteratorWorks
   111  

View as plain text