From 3decfa2b3a498591a37cd4fbc6f10b8bf508655a Mon Sep 17 00:00:00 2001 From: Mandai Yusuke Date: Fri, 6 Sep 2024 20:05:42 +0900 Subject: [PATCH 1/3] test to reproduce issue #32 --- .../convert_quadkey_and_Vertical_id_test.go | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/transform/convert_quadkey_and_Vertical_id_test.go b/transform/convert_quadkey_and_Vertical_id_test.go index 16a0875..d9a3c72 100755 --- a/transform/convert_quadkey_and_Vertical_id_test.go +++ b/transform/convert_quadkey_and_Vertical_id_test.go @@ -736,6 +736,47 @@ func TestConvertTileXYZsToExtendedSpatialIDs(t *testing.T) { 23, }, }, + { + []string{"20/85263/65423/23/0", "20/85263/65423/23/1", "20/85263/65423/23/2", "20/85264/65424/23/0", "20/85264/65424/23/1", "20/85264/65424/23/2"}, + argSet{ + []*object.TileXYZ{ + newTileXYZ( + t, + 20, + 85263, + 65423, + 23, + 0, + ), + newTileXYZ( + t, + 20, + 85263, + 65423, + 23, + 1, + ), + newTileXYZ( + t, + 20, + 85264, + 65424, + 23, + 0, + ), + newTileXYZ( + t, + 20, + 85264, + 65424, + 23, + 1, + )}, + 25, + -1, + 23, + }, + }, } for _, testCase := range testCases { expectedData := []object.ExtendedSpatialID{} @@ -830,6 +871,72 @@ func TestErrorConvertTileXYZsToExtendedSpatialIDs(t *testing.T) { } } +func ExampleConvertTileXYZsToExtendedSpatialIDs() { + inputData := []struct { + hZoom int64 + x int64 + y int64 + vZoom int64 + z int64 + }{ + { + 22, + 85263, + 65423, + 23, + 0, + }, + { + 22, + 85263, + 65423, + 23, + 1, + }, + { + 22, + 85264, + 65424, + 23, + 0, + }, + { + 22, + 85264, + 65424, + 23, + 1, + }, + } + var inputXYZ []*object.TileXYZ + for _, in := range inputData { + tile, err := object.NewTileXYZ(in.hZoom, in.x, in.y, in.vZoom, in.z) + if err != nil { + panic(err) + } + inputXYZ = append(inputXYZ, tile) + } + outputData, err := ConvertTileXYZsToExtendedSpatialIDs( + inputXYZ, + 25, + -1, + 23, + ) + if err != nil { + panic(err) + } + for _, out := range outputData { + fmt.Println(out.ID()) + } + // Unordered output: + // 22/85263/65423/23/0 + // 22/85264/65424/23/0 + // 22/85263/65423/23/1 + // 22/85264/65424/23/1 + // 22/85263/65423/23/2 + // 22/85264/65424/23/2 +} + func TestConvertExtendedSpatialIDsToSpatialIDs(t *testing.T) { testCases := []struct { expected []string From 9baeb55f263fde9b043e09e50a62b7d9219dfc06 Mon Sep 17 00:00:00 2001 From: Mandai Yusuke Date: Fri, 6 Sep 2024 22:34:39 +0900 Subject: [PATCH 2/3] fix excluding duplication process --- transform/convert_quadkey_and_Vertical_id.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/transform/convert_quadkey_and_Vertical_id.go b/transform/convert_quadkey_and_Vertical_id.go index b6a0de8..c63b2a1 100644 --- a/transform/convert_quadkey_and_Vertical_id.go +++ b/transform/convert_quadkey_and_Vertical_id.go @@ -614,7 +614,7 @@ func ConvertExtendedSpatialIDToSpatialIDs(extendedSpatialID *object.ExtendedSpat // extendedSpatialIDs :["20/85263/65423/23/-2", "20/85263/65423/23/-1"] func ConvertTileXYZsToExtendedSpatialIDs(request []*object.TileXYZ, zBaseExponent int64, zBaseOffset int64, outputVZoom int64) ([]object.ExtendedSpatialID, error) { - extendedSpatialIDsMap := make(map[int64]object.ExtendedSpatialID) + extendedSpatialIDsMap := make(map[object.ExtendedSpatialID]bool) for _, r := range request { if !extendedSpatialIDCheckZoom(r.HZoom(), outputVZoom) { @@ -627,20 +627,20 @@ func ConvertTileXYZsToExtendedSpatialIDs(request []*object.TileXYZ, zBaseExponen } for z := zMin; z <= zMax; z++ { - // 重複排除 - if _, exists := extendedSpatialIDsMap[z]; exists { - continue - } extendedSpatialID := new(object.ExtendedSpatialID) extendedSpatialID.SetX(r.X()) extendedSpatialID.SetY(r.Y()) extendedSpatialID.SetZ(z) extendedSpatialID.SetZoom(r.HZoom(), outputVZoom) - extendedSpatialIDsMap[z] = *extendedSpatialID + // 重複排除 + if _, exists := extendedSpatialIDsMap[*extendedSpatialID]; exists { + continue + } + extendedSpatialIDsMap[*extendedSpatialID] = true } } extendedSpatialIDs := make([]object.ExtendedSpatialID, 0, len(extendedSpatialIDsMap)) - for _, extendedSpatialID := range extendedSpatialIDsMap { + for extendedSpatialID := range extendedSpatialIDsMap { extendedSpatialIDs = append(extendedSpatialIDs, extendedSpatialID) } From 1cc6f1f575e434dd85449b680401bab981c09dd1 Mon Sep 17 00:00:00 2001 From: Mandai Yusuke Date: Sat, 7 Sep 2024 00:03:51 +0900 Subject: [PATCH 3/3] added test for dependent conversion -> `ConvertTilXYZsToSpatialIDs` --- .../convert_quadkey_and_Vertical_id_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/transform/convert_quadkey_and_Vertical_id_test.go b/transform/convert_quadkey_and_Vertical_id_test.go index d9a3c72..c2d9181 100755 --- a/transform/convert_quadkey_and_Vertical_id_test.go +++ b/transform/convert_quadkey_and_Vertical_id_test.go @@ -529,6 +529,54 @@ func TestConvertTileXYZsToSpatialIDs(t *testing.T) { 23, }, }, + { + []string{ + "23/0/85263/65423", + "23/1/85263/65423", + "23/2/85263/65423", + "23/0/85264/65424", + "23/1/85264/65424", + "23/2/85264/65424", + }, + argSet{ + []*object.TileXYZ{ + newTileXYZ( + t, + 23, + 85263, + 65423, + 23, + 0, + ), + newTileXYZ( + t, + 23, + 85263, + 65423, + 23, + 1, + ), + newTileXYZ( + t, + 23, + 85264, + 65424, + 23, + 0, + ), + newTileXYZ( + t, + 23, + 85264, + 65424, + 23, + 1, + )}, + 25, + -1, + 23, + }, + }, } for _, testCase := range testCases { result, err := ConvertTileXYZsToSpatialIDs(testCase.request.tile, testCase.request.zBaseExponent, testCase.request.zBaseOffset, testCase.request.outputVZoom)