From 1e1b9fc728c27ed3f3201219894ec93eedeb5994 Mon Sep 17 00:00:00 2001 From: Bert Temme Date: Wed, 12 Aug 2026 09:03:42 +0200 Subject: [PATCH] Revert "Fix scale non uniform sql" --- src/InstancesRepository.cs | 37 +++---------- src/i3dm.export.csproj | 6 +-- .../InstancesRepositoryCompatibilityTests.cs | 53 +++---------------- tests/i3dm.export.tests.csproj | 8 +-- 4 files changed, 20 insertions(+), 84 deletions(-) diff --git a/src/InstancesRepository.cs b/src/InstancesRepository.cs index d954eee..0633ca6 100644 --- a/src/InstancesRepository.cs +++ b/src/InstancesRepository.cs @@ -45,14 +45,13 @@ public static List GetInstances(NpgsqlConnection conn, string geometry var toX = ToInvariantCulture(bbox.XMax); var toY = ToInvariantCulture(bbox.YMax); + var scaleNonUniform = useScaleNonUniform ? "scale_non_uniform as scalenonuniform, " : string.Empty; conn.Open(); - var columns = GetColumns(conn, geometryTable); - var scaleSelect = GetScaleSelectFromColumns(columns, useScaleNonUniform, geometryTable); var select = keepProjection? - $"SELECT ST_ASBinary(st_force3d({geometryColumn})) as position, {scaleSelect} model, tags": - $"SELECT ST_ASBinary(ST_Transform(st_force3d({geometryColumn}), {target_epsg})) as position, {scaleSelect} model, tags"; + $"SELECT ST_ASBinary(st_force3d({geometryColumn})) as position, scale, {scaleNonUniform} model, tags": + $"SELECT ST_ASBinary(ST_Transform(st_force3d({geometryColumn}), {target_epsg})) as position, scale, {scaleNonUniform} model, tags"; - var orientationSelect = GetOrientationSelect(columns, geometryTable, useGpuInstancing); + var orientationSelect = GetOrientationSelect(conn, geometryTable, useGpuInstancing); select += orientationSelect; var sql = FormattableString.Invariant($"{select} FROM {geometryTable} where {GetWhere(geometryColumn, where, fromX, fromY, toX, toY, source_epsg, keepProjection)}"); @@ -105,8 +104,9 @@ public static (BoundingBox bbox, double zmin, double zmax) GetBoundingBoxForTabl return (bbox, zmin, zmax); } - private static string GetOrientationSelect(HashSet columns, string geometryTable, bool useGpuInstancing) + private static string GetOrientationSelect(NpgsqlConnection conn, string geometryTable, bool useGpuInstancing) { + var columns = GetColumns(conn, geometryTable); var select = GetOrientationSelectFromColumns(columns, useGpuInstancing, geometryTable, out var usesDeprecatedRotation); if (usesDeprecatedRotation) @@ -158,31 +158,6 @@ private static string GetOrientationSelectFromColumns(HashSet columns, b throw new InvalidOperationException($"Missing orientation columns for {mode}. Expected columns yaw/pitch/roll. For non-GPU you can use legacy rotation (deprecated).\n\nMigration example:\n alter table {geometryTable} add column if not exists yaw double precision default 0;\n alter table {geometryTable} add column if not exists pitch double precision default 0;\n alter table {geometryTable} add column if not exists roll double precision default 0;\n update {geometryTable} set yaw = rotation where rotation is not null;"); } - private static string GetScaleSelectFromColumns(HashSet columns, bool useScaleNonUniform, string geometryTable) - { - var hasScale = columns.Contains("scale"); - var hasScaleNonUniform = columns.Contains("scale_non_uniform"); - - if (useScaleNonUniform) - { - if (!hasScaleNonUniform) - { - throw new InvalidOperationException($"Missing column 'scale_non_uniform' on table {geometryTable}. Add it with:\n alter table {geometryTable} add column if not exists scale_non_uniform double precision[3];"); - } - - // scale column is optional when using scale_non_uniform - var scalePart = hasScale ? "scale, " : string.Empty; - return $"{scalePart}scale_non_uniform as scalenonuniform, "; - } - - if (!hasScale) - { - throw new InvalidOperationException($"Missing column 'scale' on table {geometryTable}. Add it with:\n alter table {geometryTable} add column if not exists scale double precision default 1;"); - } - - return "scale, "; - } - private static void WriteRotationDeprecatedWarning(string geometryTable) { if (_rotationDeprecatedWarningWritten) return; diff --git a/src/i3dm.export.csproj b/src/i3dm.export.csproj index 11fdf74..383b57c 100644 --- a/src/i3dm.export.csproj +++ b/src/i3dm.export.csproj @@ -24,15 +24,15 @@ - + - + - + diff --git a/tests/InstancesRepositoryCompatibilityTests.cs b/tests/InstancesRepositoryCompatibilityTests.cs index 0080e30..0f46a4f 100644 --- a/tests/InstancesRepositoryCompatibilityTests.cs +++ b/tests/InstancesRepositoryCompatibilityTests.cs @@ -36,15 +36,13 @@ public void OrientationSelect_WhenYawPitchRollMissing_NonGpuFallsBackToRotation( [Test] public void OrientationSelect_WhenYawPitchRollMissing_GpuThrows() { - Action action = () => - InvokeGetOrientationSelectFromColumns( - new HashSet(StringComparer.OrdinalIgnoreCase) - { - "rotation" - }, - useGpuInstancing: true); - - Assert.Throws(action); + Assert.Throws(() => + { + InvokeGetOrientationSelectFromColumns(new HashSet(StringComparer.OrdinalIgnoreCase) + { + "rotation" + }, useGpuInstancing: true); + }); } private static (string Select, bool UsedRotation) InvokeGetOrientationSelectFromColumns(HashSet columns, bool useGpuInstancing) @@ -60,41 +58,4 @@ private static (string Select, bool UsedRotation) InvokeGetOrientationSelectFrom var usedRotation = (bool)args[3]; return (select, usedRotation); } - - [Test] - public void ScaleSelect_WhenUseScaleNonUniformTrue_AndOnlyScaleNonUniformColumnExists_DoesNotRequireScaleColumn() - { - // Table only has scale_non_uniform, no scale column - var select = InvokeGetScaleSelectFromColumns(new HashSet(StringComparer.OrdinalIgnoreCase) - { - "scale_non_uniform" - }, useScaleNonUniform: true); - - Assert.That(select, Does.Not.Contain("scale,")); - Assert.That(select, Does.Contain("scale_non_uniform as scalenonuniform")); - } - - [Test] - public void ScaleSelect_WhenUseScaleNonUniformFalse_AndScaleColumnMissing_Throws() - { - Action action = () => - InvokeGetScaleSelectFromColumns(new HashSet(StringComparer.OrdinalIgnoreCase) - { - "scale_non_uniform" - }, useScaleNonUniform: false); - - Assert.Throws(action); - } - - private static string InvokeGetScaleSelectFromColumns(HashSet columns, bool useScaleNonUniform) - { - var method = typeof(InstancesRepository).GetMethod( - "GetScaleSelectFromColumns", - BindingFlags.NonPublic | BindingFlags.Static); - - Assert.That(method, Is.Not.Null); - - var args = new object[] { columns, useScaleNonUniform, "public.instances" }; - return (string)method!.Invoke(null, args)!; - } } diff --git a/tests/i3dm.export.tests.csproj b/tests/i3dm.export.tests.csproj index fac93e3..32075ca 100644 --- a/tests/i3dm.export.tests.csproj +++ b/tests/i3dm.export.tests.csproj @@ -7,11 +7,11 @@ - - + + - - + +