Skip to content

Commit

Permalink
fix: scanmode
Browse files Browse the repository at this point in the history
  • Loading branch information
scorix committed Jan 13, 2025
1 parent 7d04e99 commit 0c3eb84
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
17 changes: 17 additions & 0 deletions pkg/geo/grids/grid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
50 changes: 25 additions & 25 deletions pkg/geo/grids/scan_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c3eb84

Please sign in to comment.