Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Jan 16, 2025
1 parent f1f97ba commit dc8c2a9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 59 deletions.
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ issues:
linters:
- gosec

- path: "carto/*"
linters:
- asciicheck

linters-settings:
depguard:
rules:
Expand Down
2 changes: 1 addition & 1 deletion carto/proj_lambert_conformal_conic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type LambertConformalConic struct {
func NewLambertConformalConic(earthRadius float64) *LambertConformalConic {
return &LambertConformalConic{
radius: earthRadius,
origin: geom.XY{0, 0},
origin: geom.XY{X: 0, Y: 0},
stdParallels: [2]float64{0, 0},
}
}
Expand Down
12 changes: 5 additions & 7 deletions carto/proj_orthographic.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package carto

import (
. "github.com/peterstace/simplefeatures/geom"
)
import "github.com/peterstace/simplefeatures/geom"

// Orthographic allows projecting (longitude, latitude) coordinates to (x, y)
// pairs via the orthographic projection.
Expand Down Expand Up @@ -36,7 +34,7 @@ func NewOrthographic(radius float64) *Orthographic {
// SetCenterLonLat sets the center of the projection to the given (longitude,
// latitude) pair. The center have projected coordinates (0, 0) and be the
// center of the circular map.
func (m *Orthographic) SetCenter(centerLonLat XY) {
func (m *Orthographic) SetCenter(centerLonLat geom.XY) {
m.λ0 = dtor(centerLonLat.X)
φ0 := dtor(centerLonLat.Y)
m.sinφ0 = sin(φ0)
Expand All @@ -45,7 +43,7 @@ func (m *Orthographic) SetCenter(centerLonLat XY) {

// Forward converts a (longitude, latitude) pair expressed in degrees to a
// projected (x, y) pair.
func (m *Orthographic) Forward(lonLat XY) XY {
func (m *Orthographic) Forward(lonLat geom.XY) geom.XY {
var (
R = m.radius
λ = dtor(lonLat.X)
Expand All @@ -54,15 +52,15 @@ func (m *Orthographic) Forward(lonLat XY) XY {
cosφ0 = m.cosφ0
sinφ0 = m.sinφ0
)
return XY{
return geom.XY{
X: R * cos(φ) * sin(λ-λ0),
Y: R * (cosφ0*sin(φ) - sinφ0*cos(φ)*cos(λ-λ0)),
}
}

// Reverse converts a projected (x, y) pair to a (longitude, latitude) pair
// expressed in degrees.
func (m *Orthographic) Reverse(xy XY) XY {
func (m *Orthographic) Reverse(xy geom.XY) geom.XY {
var (
R = m.radius
x = xy.X
Expand Down
106 changes: 55 additions & 51 deletions carto/projections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type projectionSubTest struct {
projected geom.XY
}

func xy(x, y float64) geom.XY {
return geom.XY{X: x, Y: y}
}

func TestProjections(t *testing.T) {
for _, pc := range []struct {
name string
Expand All @@ -32,12 +36,12 @@ func TestProjections(t *testing.T) {
threshold: 1.0 / (1 << 16), // 1/65536th of a tile.
subtests: []projectionSubTest{
{
geom.XY{0, 0},
geom.XY{0.5, 0.5},
xy(0, 0),
xy(0.5, 0.5),
},
{
geom.XY{151.20756306500027, -33.86648215268569},
geom.XY{0.9200210085138897, 0.6000844973286593},
xy(151.20756306500027, -33.86648215268569),
xy(0.9200210085138897, 0.6000844973286593),
},
},
},
Expand All @@ -47,8 +51,8 @@ func TestProjections(t *testing.T) {
threshold: 1.0 / (1 << 16), // 1/65536th of a tile.
subtests: []projectionSubTest{
{
geom.XY{151.20756306500027, -33.86648215268569},
geom.XY{1929423.8980469208, 1258468.4037417925},
xy(151.20756306500027, -33.86648215268569),
xy(1929423.8980469208, 1258468.4037417925),
},
},
},
Expand All @@ -58,24 +62,24 @@ func TestProjections(t *testing.T) {
p := carto.NewOrthographic(
carto.WGS84EllipsoidMeanRadiusM,
)
p.SetCenter(geom.XY{151, -34})
p.SetCenter(xy(151, -34))
return p
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{
{
geom.XY{151, -34},
geom.XY{0, 0},
xy(151, -34),
xy(0, 0),
},
{
// 1km north of origin.
geom.XY{151, -33.99100679628548},
geom.XY{0, 1000},
xy(151, -33.99100679628548),
xy(0, 1000),
},
{
// ~100km south west of origin.
geom.XY{150.29102511044510493, -34.68753125394282932},
geom.XY{-64821.441153708925, -76672.52425247061},
xy(150.29102511044510493, -34.68753125394282932),
xy(-64821.441153708925, -76672.52425247061),
},
},
},
Expand All @@ -86,8 +90,8 @@ func TestProjections(t *testing.T) {
),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{{
geom.XY{151, -34},
geom.XY{1.679045703992921e7, -3.5626228929251498e6},
xy(151, -34),
xy(1.679045703992921e7, -3.5626228929251498e6),
}},
},
{
Expand All @@ -99,17 +103,17 @@ func TestProjections(t *testing.T) {
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{{
geom.XY{151, -34},
geom.XY{0, -3.5626228929251498e6},
xy(151, -34),
xy(0, -3.5626228929251498e6),
}},
},
{
name: "Sinusoidal",
proj: carto.NewSinusoidal(carto.WGS84EllipsoidMeanRadiusM),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{{
geom.XY{151, -34},
geom.XY{1.3919919746472625e+07, -3.780632710977439e+06},
xy(151, -34),
xy(1.3919919746472625e+07, -3.780632710977439e+06),
}},
},
{
Expand All @@ -121,8 +125,8 @@ func TestProjections(t *testing.T) {
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{{
geom.XY{151, -34},
geom.XY{0, -3.780632710977439e+06},
xy(151, -34),
xy(0, -3.780632710977439e+06),
}},
},
{
Expand All @@ -132,8 +136,8 @@ func TestProjections(t *testing.T) {
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{{
geom.XY{151, -34},
geom.XY{1.679045703992921e+07, -3.780632710977439e+06},
xy(151, -34),
xy(1.679045703992921e+07, -3.780632710977439e+06),
}},
},
{
Expand All @@ -146,8 +150,8 @@ func TestProjections(t *testing.T) {
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{{
// Gibraltar, ~480km west of 0 degrees and at ~36 degrees latitude.
geom.XY{-5.34660683624621225, 36.1335656729737309},
geom.XY{-480973.8495682527, 4.0178747161028227e+06},
xy(-5.34660683624621225, 36.1335656729737309),
xy(-480973.8495682527, 4.0178747161028227e+06),
}},
},
{
Expand All @@ -156,18 +160,18 @@ func TestProjections(t *testing.T) {
p := carto.NewAzimuthalEquidistant(
carto.WGS84EllipsoidMeanRadiusM,
)
p.SetCenter(geom.XY{0, 90})
p.SetCenter(xy(0, 90))
return p
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{
{ // Hamburg:
geom.XY{9.988519873740467, 53.434757149649016},
geom.XY{705229.5, -4004246.7},
xy(9.988519873740467, 53.434757149649016),
xy(705229.5, -4004246.7),
},
{ // Port Moresby:
geom.XY{147.1827863021232, -9.36844599194037},
geom.XY{5988277, 9285859},
xy(147.1827863021232, -9.36844599194037),
xy(5988277, 9285859),
},
},
},
Expand All @@ -177,14 +181,14 @@ func TestProjections(t *testing.T) {
p := carto.NewAzimuthalEquidistant(
carto.WGS84EllipsoidMeanRadiusM,
)
p.SetCenter(geom.XY{0, 0})
p.SetCenter(xy(0, 0))
return p
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{
{ // Cape Town:
geom.XY{18.483735820900083, -33.95848592499432},
geom.XY{1805674, -3835659},
xy(18.483735820900083, -33.95848592499432),
xy(1805674, -3835659),
},
},
},
Expand All @@ -194,19 +198,19 @@ func TestProjections(t *testing.T) {
p := carto.NewEquidistantConic(
carto.WGS84EllipsoidMeanRadiusM,
)
p.SetOrigin(geom.XY{X: -60, Y: -32})
p.SetOrigin(xy(-60, -32))
p.SetStandardParallels(-5, -42)
return p
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{
{ // Rio de Janeiro:
geom.XY{X: -43.2, Y: -22.8},
geom.XY{1629961.7759447654, 929251.645477184},
xy(-43.2, -22.8),
xy(1629961.7759447654, 929251.645477184),
},
{ // Baltimore:
geom.XY{X: -76.6, Y: 39.3},
geom.XY{X: -2392910.752006106, Y: 7792228.9404544085},
xy(-76.6, 39.3),
xy(-2392910.752006106, 7792228.9404544085),
},
},
},
Expand All @@ -216,15 +220,15 @@ func TestProjections(t *testing.T) {
p := carto.NewEquidistantConic(
carto.WGS84EllipsoidMeanRadiusM,
)
p.SetOrigin(geom.XY{X: 95, Y: 30})
p.SetOrigin(xy(95, 30))
p.SetStandardParallels(15, 65)
return p
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{
{ // Beijing:
geom.XY{X: 116.44497408510593, Y: 39.890737551498475},
geom.XY{X: 1643407.6, Y: 1292149.5},
xy(116.44497408510593, 39.890737551498475),
xy(1643407.6, 1292149.5),
},
},
},
Expand All @@ -234,19 +238,19 @@ func TestProjections(t *testing.T) {
p := carto.NewLambertConformalConic(
carto.WGS84EllipsoidMeanRadiusM,
)
p.SetOrigin(geom.XY{X: -96, Y: 40})
p.SetOrigin(xy(-96, 40))
p.SetStandardParallels(50, 70)
return p
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{
{ // Toronto:
geom.XY{X: -79.3832, Y: 43.6532},
geom.XY{X: 1353292.7229285287, Y: 590902.0666354574},
xy(-79.3832, 43.6532),
xy(1353292.7229285287, 590902.0666354574),
},
{ // Vancouver:
geom.XY{X: -123.1216, Y: 49.2827},
geom.XY{X: -1916086.3118012992, Y: 1453088.303860319},
xy(-123.1216, 49.2827),
xy(-1916086.3118012992, 1453088.303860319),
},
},
},
Expand All @@ -256,19 +260,19 @@ func TestProjections(t *testing.T) {
p := carto.NewAlbersEqualAreaConic(
carto.WGS84EllipsoidMeanRadiusM,
)
p.SetOrigin(geom.XY{X: 132, Y: 0})
p.SetOrigin(xy(132, 0))
p.SetStandardParallels(-18, -36)
return p
}(),
threshold: 1e-3, // 1mm
subtests: []projectionSubTest{
{ // Sydney:
geom.XY{151.2146821, -33.8574973},
geom.XY{1757815.279206157, -3843578.921069043},
xy(151.2146821, -33.8574973),
xy(1757815.279206157, -3843578.921069043),
},
{ // Perth:
geom.XY{115.5397172, -31.9949202},
geom.XY{-1534150.6162269458, -3601473.816874394},
xy(115.5397172, -31.9949202),
xy(-1534150.6162269458, -3601473.816874394),
},
},
},
Expand Down

0 comments on commit dc8c2a9

Please sign in to comment.