Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/VersionHandler/Resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.14.1
2.14.2
32 changes: 32 additions & 0 deletions Tests/ViewsTests/GeodesicGeometryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ struct GeodesicGeometryTests {
.squareRoot()
}

private struct QuantizedVertex: Hashable {
let x, y, z: Int
}

/// Quantized coordinate key so the same centroid (reused by value across
/// several struts) collapses to one identity. The 80 centroids are ~0.36
/// apart on the unit sphere, far above the 1e-6 rounding floor, so distinct
/// vertices never collide.
private func key(_ v: Vertex3D) -> QuantizedVertex {
QuantizedVertex(
x: Int((v.x * 1_000_000).rounded()),
y: Int((v.y * 1_000_000).rounded()),
z: Int((v.z * 1_000_000).rounded()))
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

severity

辞書のキーとして [Int] を使用する代わりに、専用の Hashablestruct を定義することを検討してください。これにより、意図が明確になり、配列の動的確保(ヒープ割り当て)も避けられます。

    private struct QuantizedVertex: Hashable {
        let x, y, z: Int
    }

    private func key(_ v: Vertex3D) -> QuantizedVertex {
        QuantizedVertex(
            x: Int((v.x * 1_000_000).rounded()),
            y: Int((v.y * 1_000_000).rounded()),
            z: Int((v.z * 1_000_000).rounded())
        )
    }

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action

ご提案どおり専用の Hashable struct QuantizedVertex に置き換えました。意図が明確になり、辺ごとの [Int] 配列確保も 解消 しています。ad0f3af


@Test("dual of the freq-2 icosphere has exactly 120 edges")
func edgeCount() {
// 80 triangles → 120 manifold edges → 120 dual struts. Any other count
Expand All @@ -38,4 +53,21 @@ struct GeodesicGeometryTests {
#expect(distance(a, b) > 1e-6)
}
}

@Test("struts form a closed trivalent cage — 80 hubs, each of degree 3")
func trivalentCage() {
// Each strut endpoint is the centroid of one of the 80 icosphere
// triangles, i.e. a vertex of the Goldberg dual. A closed manifold
// makes every triangle share all 3 of its edges, so each centroid is
// trivalent. 80 hubs × 3 / 2 = 120 struts — consistent with edgeCount.
// A broken face list or non-manifold subdivision would drop a hub or

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

severity

flatMap を使用して中間配列を作成する代わりに、reduce で直接集計することで、不要な中間ステップを排除できます。これはプロジェクトの「No Unnecessary Intermediate Steps」という規約により適合します。

        let degree = GeodesicGeometry.edges
            .reduce(into: [[Int]: Int]()) { dict, edge in
                dict[key(edge.0), default: 0] += 1
                dict[key(edge.1), default: 0] += 1
            }

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action

flatMap の中間配列を 排除 し、両端点を1つの reduce(into:) に直接畳み込みました。ad0f3af

// skew a degree, which a raw edge count alone can miss.
let degree = GeodesicGeometry.edges
.reduce(into: [QuantizedVertex: Int]()) { counts, edge in
counts[key(edge.0), default: 0] += 1
counts[key(edge.1), default: 0] += 1
}
#expect(degree.count == 80)
#expect(degree.values.allSatisfy { $0 == 3 })
}
}
Loading