From 0c3eb84e64236e67c105c2719fb04f4026a84b41 Mon Sep 17 00:00:00 2001 From: scorix Date: Mon, 13 Jan 2025 15:56:42 +0800 Subject: [PATCH] fix: scanmode --- pkg/geo/grids/grid_test.go | 17 +++++++++++++ pkg/geo/grids/scan_mode.go | 50 +++++++++++++++++++------------------- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/pkg/geo/grids/grid_test.go b/pkg/geo/grids/grid_test.go index 5940dfe..e148b1d 100644 --- a/pkg/geo/grids/grid_test.go +++ b/pkg/geo/grids/grid_test.go @@ -736,3 +736,20 @@ func BenchmarkGridPoint(b *testing.B) { } }) } + +func TestTianjiGrid(t *testing.T) { + grid := latlon.NewLatLonGrid(-89.95, 89.95, 0.05, 359.95, 0.1, 0.1) + + var tests = []gridTestCase{ + // 网格点精确匹配 + {name: "First Column Start", lat: -89.95, lon: 0.05, expectedIdx: 0, gridLat: -89.95, gridLon: 0.05}, + {name: "First Column Second Point", lat: -89.95, lon: 0.15, expectedIdx: 1, gridLat: -89.95, gridLon: 0.15}, + {name: "First Column End", lat: -89.95, lon: 359.95, expectedIdx: 3599, gridLat: -89.95, gridLon: 359.95}, + {name: "Second Column Start", lat: -89.85, lon: 0.05, expectedIdx: 3600, gridLat: -89.85, gridLon: 0.05}, + {name: "Second Column End", lat: -89.85, lon: 359.95, expectedIdx: 3600 + 3599, gridLat: -89.85, gridLon: 359.95}, + {name: "Last Column Start", lat: 89.95, lon: 0.05, expectedIdx: 3600 * 1799, gridLat: 89.95, gridLon: 0.05}, + {name: "Last Column End", lat: 89.95, lon: 359.95, expectedIdx: 3600*1799 + 3599, gridLat: 89.95, gridLon: 359.95}, + } + + runGridTests(t, grid, tests, grids.ScanModePositiveJ) +} diff --git a/pkg/geo/grids/scan_mode.go b/pkg/geo/grids/scan_mode.go index 91e44c9..b096916 100644 --- a/pkg/geo/grids/scan_mode.go +++ b/pkg/geo/grids/scan_mode.go @@ -8,73 +8,73 @@ type ScanMode uint8 const ( // Bit 1: i (x) direction scanning - ScanModePositiveI ScanMode = 0 // Points scan in +i direction - ScanModeNegativeI ScanMode = 1 // Points scan in -i direction + ScanModePositiveI ScanMode = 0 // Points scan in +i direction + ScanModeNegativeI ScanMode = 0b10000000 // Points scan in -i direction // Bit 2: j (y) direction scanning - ScanModeNegativeJ ScanMode = 0 // Points scan in -j direction - ScanModePositiveJ ScanMode = 2 // Points scan in +j direction + ScanModeNegativeJ ScanMode = 0 // Points scan in -j direction + ScanModePositiveJ ScanMode = 0b01000000 // Points scan in +j direction // Bit 3: Adjacent points - ScanModeConsecutiveI ScanMode = 0 // Adjacent points in i direction are consecutive - ScanModeConsecutiveJ ScanMode = 4 // Adjacent points in j direction are consecutive + ScanModeConsecutiveI ScanMode = 0 // Adjacent points in i direction are consecutive + ScanModeConsecutiveJ ScanMode = 0b00100000 // Adjacent points in j direction are consecutive // Bit 4: Row direction - ScanModeSameDirection ScanMode = 0 // All rows scan in same direction - ScanModeOppositeRows ScanMode = 8 // Adjacent rows scan in opposite direction + ScanModeSameDirection ScanMode = 0 // All rows scan in same direction + ScanModeOppositeRows ScanMode = 0b00010000 // Adjacent rows scan in opposite direction // Bit 5: Odd row offset - ScanModeNoOddOffset ScanMode = 0 // Points within odd rows not offset - ScanModeOddOffset ScanMode = 16 // Points within odd rows offset by Di/2 + ScanModeNoOddOffset ScanMode = 0 // Points within odd rows not offset + ScanModeOddOffset ScanMode = 0b00001000 // Points within odd rows offset by Di/2 // Bit 6: Even row offset - ScanModeNoEvenOffset ScanMode = 0 // Points within even rows not offset - ScanModeEvenOffset ScanMode = 32 // Points within even rows offset by Di/2 + ScanModeNoEvenOffset ScanMode = 0 // Points within even rows not offset + ScanModeEvenOffset ScanMode = 0b00000100 // Points within even rows offset by Di/2 // Bit 7: J direction offset - ScanModeNoJOffset ScanMode = 0 // Points not offset in j direction - ScanModeJOffset ScanMode = 64 // Points offset by Dj/2 in j direction + ScanModeNoJOffset ScanMode = 0 // Points not offset in j direction + ScanModeJOffset ScanMode = 0b00000010 // Points offset by Dj/2 in j direction // Bit 8: Row/Column point counts - ScanModeRegularPoints ScanMode = 0 // Regular Ni x Nj points - ScanModeOffsetPoints ScanMode = 128 // Points may be reduced based on offsets + ScanModeRegularPoints ScanMode = 0 // Regular Ni x Nj points + ScanModeOffsetPoints ScanMode = 0b00000001 // Points may be reduced based on offsets ) // Helper methods to check individual bits func (s ScanMode) IsNegativeI() bool { - return s&1 == 1 + return s&ScanModeNegativeI == ScanModeNegativeI } func (s ScanMode) IsPositiveJ() bool { - return s&2 == 2 + return s&ScanModePositiveJ == ScanModePositiveJ } func (s ScanMode) IsConsecutiveI() bool { - return s&4 == 0 + return s&ScanModeConsecutiveJ == 0 } func (s ScanMode) IsConsecutiveJ() bool { - return s&4 == 4 + return s&ScanModeConsecutiveJ == ScanModeConsecutiveJ } func (s ScanMode) HasOppositeRows() bool { - return s&8 == 8 + return s&ScanModeOppositeRows == ScanModeOppositeRows } func (s ScanMode) HasOddOffset() bool { - return s&16 == 16 + return s&ScanModeOddOffset == ScanModeOddOffset } func (s ScanMode) HasEvenOffset() bool { - return s&32 == 32 + return s&ScanModeEvenOffset == ScanModeEvenOffset } func (s ScanMode) HasJOffset() bool { - return s&64 == 64 + return s&ScanModeJOffset == ScanModeJOffset } func (s ScanMode) HasOffsetPoints() bool { - return s&128 == 128 + return s&ScanModeOffsetPoints == ScanModeOffsetPoints } // String returns a human readable description of the scan mode