Skip to content

Commit

Permalink
chore: move Float64Slice functions into pj.go
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Oct 31, 2024
1 parent 524bfeb commit f8e60d6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 75 deletions.
23 changes: 0 additions & 23 deletions float64slice.go

This file was deleted.

52 changes: 0 additions & 52 deletions float64slice_test.go

This file was deleted.

22 changes: 22 additions & 0 deletions pj.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func (pj *PJ) ForwardFlatCoords(flatCoords []float64, stride, zIndex, mIndex int
return pj.TransFlatCoords(DirectionFwd, flatCoords, stride, zIndex, mIndex)
}

// ForwardFloat64Slice transforms float64 in place in the forward direction.
func (pj *PJ) ForwardFloat64Slice(float64Slice []float64) ([]float64, error) {
return pj.TransFloat64Slice(DirectionFwd, float64Slice)
}

// Geod returns the distance, forward azimuth, and reverse azimuth between a and b.
func (pj *PJ) Geod(a, b Coord) (float64, float64, float64) {
pj.context.Lock()
Expand Down Expand Up @@ -130,6 +135,11 @@ func (pj *PJ) InverseFlatCoords(flatCoords []float64, stride, zIndex, mIndex int
return pj.TransFlatCoords(DirectionInv, flatCoords, stride, zIndex, mIndex)
}

// InverseFloat64Slice transforms float64 in place in the forward direction.
func (pj *PJ) InverseFloat64Slice(float64Slice []float64) ([]float64, error) {
return pj.TransFloat64Slice(DirectionInv, float64Slice)
}

// LPDist returns the geodesic distance between a and b in geodetic coordinates.
func (pj *PJ) LPDist(a, b Coord) float64 {
pj.context.Lock()
Expand Down Expand Up @@ -226,6 +236,18 @@ func (pj *PJ) TransFlatCoords(direction Direction, flatCoords []float64, stride,
return pj.TransGeneric(direction, x, sx, nx, y, sy, ny, z, sz, nz, m, sm, nm)
}

// TransFloat64Slice transforms a []float64 in place.
func (pj *PJ) TransFloat64Slice(direction Direction, float64Slice []float64) ([]float64, error) {
var coord Coord
copy(coord[:], float64Slice)
transCoord, err := pj.Trans(direction, coord)
if err != nil {
return nil, err
}
copy(float64Slice, transCoord[:])
return float64Slice, nil
}

// TransGeneric transforms a series of coordinates.
func (pj *PJ) TransGeneric(direction Direction, x *float64, sx, nx int, y *float64, sy, ny int, z *float64, sz, nz int, m *float64, sm, nm int) error {
pj.context.Lock()
Expand Down
41 changes: 41 additions & 0 deletions pj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,47 @@ func TestPJ_TransFlatCoords(t *testing.T) {
}
}

func TestPJ_TransFloat64Slice(t *testing.T) {
for i, tc := range []struct {
float64Slice []float64
expected []float64
delta float64
}{
{
float64Slice: nil,
expected: nil,
},
{
float64Slice: []float64{},
expected: []float64{},
},
{
float64Slice: []float64{723134.1266446244, 474831.4869142064},
expected: []float64{54.371652, 18.612462},
delta: 1e-14,
},
{
float64Slice: []float64{723134.1266446244, 474831.4869142064, 11.1},
expected: []float64{54.371652, 18.612462, 11.1},
delta: 1e-14,
},
{
float64Slice: []float64{723134.1266446244, 474831.4869142064, 11.1, 1},
expected: []float64{54.371652, 18.612462, 11.1, 1},
delta: 1e-14,
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
pj, err := proj.NewCRSToCRS("EPSG:2180", "EPSG:4326", nil)
assert.NoError(t, err)
float64Slice := slices.Clone(tc.float64Slice)
actual, err := pj.ForwardFloat64Slice(float64Slice)
assert.NoError(t, err)
assertInDeltaFloat64Slice(t, tc.expected, actual, tc.delta)
})
}
}

func TestPJ_NormalizeForVisualizationForNorthingEastingCRS(t *testing.T) {
defer runtime.GC()

Expand Down

0 comments on commit f8e60d6

Please sign in to comment.