go-hep.org/x/hep@v0.38.1/fastjet/internal/predicates/incircle_test.go (about)

     1  // Copyright ©2017 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package predicates
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestIncircle(t *testing.T) {
    12  	tests := []struct {
    13  		x1, y1, x2, y2, x3, y3, x, y float64
    14  		want                         RelativePosition
    15  	}{
    16  		{1, 1, 3, 1, 2, 2, 2, 1.5, Inside},
    17  		{1, 1, 3, 1, 2, 2, 2, 3, Outside},
    18  		{1, 1, 3, 1, 2, 2, 2, 0, On},
    19  		{1, 2, 3, 2, 2, 3, 2.7071066, 2.7071066, Inside},
    20  		{1, 2, 3, 2, 2, 3, 2.7071068, 2.7071068, Outside},
    21  		{0, 10, -10, 0, 0, -10, 6, 8, On},
    22  		{0, 10, -10, 0, 0, -10, 6, 7.99, Inside},
    23  		{0, 10, -10, 0, 0, -10, 6, 8.01, Outside},
    24  		{1.5625, 1.375, 1.0625, .875, 1, 1, 1.25, .75, On},
    25  		{1.5625, 1.375, 1, 1, 1.0625, .875, 1.2500001, .75, Inside},
    26  		{1.5625, 1.375, 1, 1, 1.0625, .875, 1.2499999, .75, Outside},
    27  	}
    28  	for _, test := range tests {
    29  		got := Incircle(test.x1, test.y1, test.x2, test.y2, test.x3, test.y3, test.x, test.y)
    30  		if got != test.want {
    31  			t.Fatalf("Incircle(%v,%v,%v,%v,%v,%v,%v,%v) = %v, want = %v", test.x1, test.y1, test.x2, test.y2, test.x3, test.y3, test.x, test.y, got, test.want)
    32  		}
    33  	}
    34  }
    35  
    36  func BenchmarkSimpleIncircle(b *testing.B) {
    37  	tests := []struct {
    38  		x1, y1, x2, y2, x3, y3, x, y float64
    39  	}{
    40  		{1, 1, 3, 1, 2, 2, 2, 1.5},
    41  		{1, 1, 3, 1, 2, 2, 2, 3},
    42  		{1, 1, 3, 1, 2, 2, 2, 0},
    43  		{1, 2, 3, 2, 2, 3, 2.707106, 2.707106},
    44  		{1, 2, 3, 2, 2, 3, 2.707107, 2.707107},
    45  		{0, 10, -10, 0, 0, -10, 6, 8},
    46  		{0, 10, -10, 0, 0, -10, 6, 7.99},
    47  		{0, 10, -10, 0, 0, -10, 6, 8.01},
    48  	}
    49  	b.ResetTimer()
    50  	for i := 0; i < b.N; i++ {
    51  		for _, test := range tests {
    52  			simpleIncircle(test.x1, test.y1, test.x2, test.y2, test.x3, test.y3, test.x, test.y)
    53  		}
    54  	}
    55  }
    56  
    57  func BenchmarkMatIncircle(b *testing.B) {
    58  	tests := []struct {
    59  		x1, y1, x2, y2, x3, y3, x, y float64
    60  	}{
    61  		{1, 1, 3, 1, 2, 2, 2, 1.5},
    62  		{1, 1, 3, 1, 2, 2, 2, 3},
    63  		{1, 1, 3, 1, 2, 2, 2, 0},
    64  		{1, 2, 3, 2, 2, 3, 2.707106, 2.707106},
    65  		{1, 2, 3, 2, 2, 3, 2.707107, 2.707107},
    66  		{0, 10, -10, 0, 0, -10, 6, 8},
    67  		{0, 10, -10, 0, 0, -10, 6, 7.99},
    68  		{0, 10, -10, 0, 0, -10, 6, 8.01},
    69  	}
    70  	b.ResetTimer()
    71  	for i := 0; i < b.N; i++ {
    72  		for _, test := range tests {
    73  			matIncircle(test.x1, test.y1, test.x2, test.y2, test.x3, test.y3, test.x, test.y)
    74  		}
    75  	}
    76  }
    77  
    78  func BenchmarkRobustIncircle(b *testing.B) {
    79  	tests := []struct {
    80  		x1, y1, x2, y2, x3, y3, x, y float64
    81  	}{
    82  		{1, 1, 3, 1, 2, 2, 2, 1.5},
    83  		{1, 1, 3, 1, 2, 2, 2, 3},
    84  		{1, 1, 3, 1, 2, 2, 2, 0},
    85  		{1, 2, 3, 2, 2, 3, 2.707106, 2.707106},
    86  		{1, 2, 3, 2, 2, 3, 2.707107, 2.707107},
    87  		{0, 10, -10, 0, 0, -10, 6, 8},
    88  		{0, 10, -10, 0, 0, -10, 6, 7.99},
    89  		{0, 10, -10, 0, 0, -10, 6, 8.01},
    90  	}
    91  	b.ResetTimer()
    92  	for i := 0; i < b.N; i++ {
    93  		for _, test := range tests {
    94  			robustIncircle(setBig(test.x1), setBig(test.y1), setBig(test.x2), setBig(test.y2), setBig(test.x3), setBig(test.y3), setBig(test.x), setBig(test.y))
    95  		}
    96  	}
    97  }