github.com/pavlo67/common@v0.5.3/common/mathlib/plane/chain_projections_test1.go (about)

     1  package plane
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestCutWithProjections(t *testing.T) {
     9  	tests := []struct {
    10  		name string
    11  		pCh  PolyChain
    12  		pr0  ProjectionOnPolyChain
    13  		pr1  ProjectionOnPolyChain
    14  		want PolyChain
    15  	}{
    16  		{
    17  			name: "",
    18  			pCh:  PolyChain{{X: 2.3, Y: 458}, {X: 91, Y: 427.5}},
    19  			pr0:  ProjectionOnPolyChain{N: 1, Position: 0, Point2: Point2{X: 91, Y: 427.5}},
    20  			pr1:  ProjectionOnPolyChain{N: 0, Position: 9.7, Point2: Point2{X: 11.5, Y: 455}},
    21  			want: PolyChain{{X: 91, Y: 427.5}, {11.5, 455}},
    22  		},
    23  	}
    24  	for _, tt := range tests {
    25  		t.Run(tt.name, func(t *testing.T) {
    26  			if got := CutWithProjections(tt.pCh, tt.pr0, tt.pr1); !reflect.DeepEqual(got, tt.want) {
    27  				t.Errorf("CutWithProjections() = %v, want %v", got, tt.want)
    28  			}
    29  		})
    30  	}
    31  }
    32  
    33  func TestDistanceToSegment(t *testing.T) {
    34  
    35  	tests := []struct {
    36  		name    string
    37  		p       Point2
    38  		segment Segment
    39  		want    float64
    40  	}{
    41  		{
    42  			name:    "",
    43  			p:       Point2{203.77788799006555, 564.5811856102348},
    44  			segment: Segment{{230.79193808962214, 591.2694925293472}, {145.99999999999994, 507.50000000000006}},
    45  			want:    0,
    46  		},
    47  	}
    48  	for _, tt := range tests {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			got, _ := tt.p.DistanceToSegment(tt.segment)
    51  			if got != tt.want {
    52  				t.Errorf("DistanceToSegment() got = %v, want %v", got, tt.want)
    53  			}
    54  		})
    55  	}
    56  }