Skip to content

Commit 0dbb677

Browse files
authored
C#ラッパーのリファクタリング (Synesthesias#140)
* C# NativeMethodsリファクタ中 * 同上 * 同上 * 同上 * NativeMethodsの各structを別のファイルに移動中 * 同上 * NativeMethods削除(移行)完了 * NativeMethodsアクセスレベル整理 * publicをinternalに変更中 * 同上 * 同上 * 同上 * GeoReferenceの来てクラスをPInvokeDisposableに置き換え * C#で名前空間変更、傾向に対処 * C# NativeVectorDatasetMetadataのテストを少し追加 * 表面的なリファクタ * publicからprivateにできるものをprivateに * Windowsのロケールが英語のときにUnityテストケースでエラーになる問題を修正しました。
1 parent 8977715 commit 0dbb677

File tree

78 files changed

+2030
-2031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2030
-2031
lines changed

src/c_wrapper/gml_file_c.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ extern "C" {
5454
GmlFile* const out_gml_file_info
5555
) {
5656
API_TRY {
57+
if(!gml_file_info->isValid()){
58+
return APIResult::ErrorValueIsInvalid;
59+
}
5760
const auto destination_root_path = std::string(destination_root_path_chars);
5861
gml_file_info->fetch(destination_root_path, *out_gml_file_info);
5962
return APIResult::Success;

src/c_wrapper/libplateau_c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,6 @@ namespace libplateau {
377377
// このenumを戻り値にすると良いです。
378378
enum APIResult {
379379
Success, ErrorUnknown, ErrorValueNotFound, ErrorLoadingCityGml, ErrorIndexOutOfBounds, ErrorFileSystem,
380-
ErrorInvalidArgument
380+
ErrorInvalidArgument, ErrorValueIsInvalid
381381
};
382382
}

src/dataset/gml_file.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ namespace plateau::dataset {
231231
auto src = fs::path(src_base_path).append(path).make_preferred();
232232
auto dest = fs::path(dest_base_path).append(path).make_preferred();
233233
if (!fs::exists(src)) {
234-
std::cout << "file not exist : " << src.string() << std::endl;
234+
std::cout << "file not exist : " << src.u8string() << std::endl;
235235
continue;
236236
}
237237
fs::create_directories(dest.parent_path());
@@ -323,6 +323,7 @@ namespace plateau::dataset {
323323
}
324324

325325
void GmlFile::fetch(const std::string& destination_root_path, GmlFile& copied_gml_file) const {
326+
if(!isValid()) throw std::runtime_error("gml file is invalid.");
326327
auto gml_relative_path_from_udx = fs::path();
327328
auto destination_udx_path = fs::path();
328329
auto gml_destination_path = fs::path();

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/Basemap/TileProjectionTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using PLATEAU.Basemap;
3-
using PLATEAU.Interop;
43

54
namespace PLATEAU.Test.Basemap
65
{

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/Basemap/VectorTileDownloaderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.IO;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using PLATEAU.Basemap;
4-
using PLATEAU.Interop;
4+
using PLATEAU.Native;
55

66
namespace PLATEAU.Test.Basemap
77
{

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/CityGML/TestUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using PLATEAU.CityGML;
4-
using PLATEAU.Interop;
4+
using PLATEAU.Native;
55

66
namespace PLATEAU.Test.CityGML {
7-
public static class TestUtil {
7+
internal static class TestUtil {
88

99
private static readonly Dictionary<GmlFileCase, string> GmlPaths = new Dictionary<GmlFileCase, string>()
1010
{

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/Dataset/DatasetAccessorTest.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
2-
using System.Diagnostics;
32
using System.IO;
43
using System.Linq;
54
using Microsoft.VisualStudio.TestTools.UnitTesting;
65
using PLATEAU.Dataset;
76
using PLATEAU.Geometries;
8-
using PLATEAU.Interop;
7+
using PLATEAU.Native;
98
using PLATEAU.Network;
109

1110
namespace PLATEAU.Test.Dataset
@@ -141,16 +140,9 @@ private static void TestCenterPoint(DatasetSource source)
141140
using var collection = source.Accessor;
142141
var meshCodes = collection.MeshCodes.ToArray();
143142
Assert.IsTrue(meshCodes.Length > 0);
144-
foreach (var meshCode in meshCodes)
145-
{
146-
var extent = meshCode.Extent;
147-
var min = extent.Min;
148-
var max = extent.Max;
149-
Console.WriteLine($"{min.Latitude}, {min.Longitude}, {min.Height}");
150-
}
151143

152144
PlateauVector3d center;
153-
using (var geoRef = new GeoReference(new PlateauVector3d(0, 0, 0), 1.0f, CoordinateSystem.EUN, 9))
145+
using (var geoRef = GeoReference.Create(new PlateauVector3d(0, 0, 0), 1.0f, CoordinateSystem.EUN, 9))
154146
{
155147
center = collection.CalculateCenterPoint(geoRef);
156148
}

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/Dataset/GmlFileTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public void SearchCodelistPathsAndTexturePaths()
101101
using var accessor = sourceLocal.Accessor;
102102
var gmls = accessor.GetGmlFiles(PredefinedCityModelPackage.Building);
103103
var gml = gmls.At(0);
104-
var codelistPaths = gml.SearchAllCodelistPathsInGml().ToCSharpArray();
105-
var imagePaths = gml.SearchAllImagePathsInGml().ToCSharpArray();
104+
var codelistPaths = gml.SearchAllCodelistPathsInGml();
105+
var imagePaths = gml.SearchAllImagePathsInGml();
106106
var expectedCodelists = new[]
107107
{
108108
"../../codelists/Common_districtsAndZonesType.xml",
@@ -133,13 +133,13 @@ public void Fetch_Server_Downloads_Files()
133133
using var source = DatasetSource.Create(new DatasetSourceConfig(true, "", "23ku"));
134134
using var accessor = source.Accessor;
135135
// パスに日本語名を含むケースでテストします。
136-
var testDir = Directory.CreateDirectory("テスト用一時フォルダ");
137-
136+
var testDir = new DirectoryInfo("テスト用一時フォルダ");
138137
if(Directory.Exists(testDir.FullName)) Directory.Delete(testDir.FullName, true);
138+
Directory.CreateDirectory(testDir.FullName);
139+
140+
accessor.GetGmlFiles(PredefinedCityModelPackage.Building).At(0).Fetch(testDir.FullName);
139141

140-
var gmls = accessor.GetGmlFiles(PredefinedCityModelPackage.Building);
141142
Console.WriteLine(testDir.FullName);
142-
var fetchedGml = gmls.At(0).Fetch(testDir.FullName);
143143
bool textureExist = File.Exists(Path.Combine(testDir.FullName,
144144
"13100_tokyo23-ku_2020_citygml_3_2_op/udx/bldg/53392642_bldg_6697_appearance/hnap0034.jpg"));
145145
bool codelistExist = File.Exists(Path.Combine(testDir.FullName,

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/Dataset/MeshCodeTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using PLATEAU.Dataset;
3-
using PLATEAU.Interop;
3+
using PLATEAU.Native;
44

55
namespace PLATEAU.Test.Dataset
66
{

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/Geom/GeoReferenceTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using PLATEAU.Geometries;
4-
using PLATEAU.Interop;
4+
using PLATEAU.Native;
55

66
namespace PLATEAU.Test.Geom
77
{
@@ -42,7 +42,7 @@ public void When_GeoCoordinate_Is_OriginOfZone_Then_Project_Returns_Zero()
4242
/// </summary>
4343
private static void CheckZoneIDOrigin(int zoneID, double latitude, double longitude)
4444
{
45-
using var geoReference = new GeoReference(
45+
using var geoReference = GeoReference.Create(
4646
new PlateauVector3d(0, 0, 0),
4747
1f, CoordinateSystem.WUN, zoneID
4848
);
@@ -80,7 +80,7 @@ public void Unproject_Converts_Local_Position_To_GeoCoordinate()
8080

8181
private static void CheckUnproject(PlateauVector3d point, GeoCoordinate targetLatLon, PlateauVector3d referencePoint, float unitScale, CoordinateSystem coordinateSystem, int zoneID)
8282
{
83-
using var geoReference = new GeoReference(referencePoint, unitScale, coordinateSystem, zoneID);
83+
using var geoReference = GeoReference.Create(referencePoint, unitScale, coordinateSystem, zoneID);
8484

8585
var latLon = geoReference.Unproject(point);
8686
Assert.IsTrue(Math.Abs(latLon.Latitude - targetLatLon.Latitude) < 0.00000001);//およそ1mm相当の誤差以内か
@@ -99,7 +99,7 @@ public void Unproject_Is_Inverse_Of_Project()
9999
[TestMethod]
100100
public void Getter_Returns_Value()
101101
{
102-
var geoReference = new GeoReference(
102+
using var geoReference = GeoReference.Create(
103103
new PlateauVector3d(1, 2, 3), 4, CoordinateSystem.ENU, 5
104104
);
105105
Assert.AreEqual(1, geoReference.ReferencePoint.X);
@@ -112,7 +112,7 @@ public void Getter_Returns_Value()
112112

113113
private static void CheckProjectUnproject(PlateauVector3d referencePoint, float unitScale, CoordinateSystem coordinateSystem, int zoneID)
114114
{
115-
using var geoReference = new GeoReference(referencePoint, unitScale, coordinateSystem, zoneID);
115+
using var geoReference = GeoReference.Create(referencePoint, unitScale, coordinateSystem, zoneID);
116116
var latitude = 35.62439457074015;
117117
var longitude = 139.74256342432295;
118118
var xyz = geoReference.Project(new GeoCoordinate(latitude, longitude, 0.0));

0 commit comments

Comments
 (0)