1 // Copyright 2019 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 s1_test 16 17 import ( 18 "fmt" 19 "math" 20 21 "github.com/golang/geo/s1" 22 ) 23 24 func ExampleInterval_DirectedHausdorffDistance() { 25 // Small interval around the midpoints between quadrants, such that 26 // the center of each interval is offset slightly CCW from the midpoint. 27 mid := s1.IntervalFromEndpoints(math.Pi/2-0.01, math.Pi/2+0.02) 28 fmt.Println("empty to empty: ", s1.EmptyInterval().DirectedHausdorffDistance(s1.EmptyInterval())) 29 fmt.Println("empty to mid12: ", s1.EmptyInterval().DirectedHausdorffDistance(mid)) 30 fmt.Println("mid12 to empty: ", mid.DirectedHausdorffDistance(s1.EmptyInterval())) 31 32 // Quadrant pair. 33 quad2 := s1.IntervalFromEndpoints(0, -math.Pi) 34 // Quadrant triple. 35 quad3 := s1.IntervalFromEndpoints(0, -math.Pi/2) 36 fmt.Println("quad12 to quad123 ", quad2.DirectedHausdorffDistance(quad3)) 37 38 // An interval whose complement center is 0. 39 in := s1.IntervalFromEndpoints(3, -3) 40 41 ivs := []s1.Interval{s1.IntervalFromEndpoints(-0.1, 0.2), s1.IntervalFromEndpoints(0.1, 0.2), s1.IntervalFromEndpoints(-0.2, -0.1)} 42 for _, iv := range ivs { 43 fmt.Printf("dist from %v to in: %f\n", iv, iv.DirectedHausdorffDistance(in)) 44 } 45 // Output: 46 // empty to empty: 0.0000000 47 // empty to mid12: 0.0000000 48 // mid12 to empty: 180.0000000 49 // quad12 to quad123 0.0000000 50 // dist from [-0.1000000, 0.2000000] to in: 3.000000 51 // dist from [0.1000000, 0.2000000] to in: 2.900000 52 // dist from [-0.2000000, -0.1000000] to in: 2.900000 53 } 54