Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
135 lines
5.8 KiB
TypeScript
135 lines
5.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|||
|
|
import * as THREE from "three";
|
||
|
|
import {
|
||
|
|
MAX_SVG_GEOMETRY_ELEMENTS,
|
||
|
|
analyzeTriangleSoup,
|
||
|
|
buildSvgExtrusionFromPaths,
|
||
|
|
normalizeSvgUseReferences,
|
||
|
|
validateClosedSolidTriangleSoup,
|
||
|
|
validateSvgSourcePreflight,
|
||
|
|
} from "@/lib/svgImport";
|
||
|
|
|
||
|
|
function shapePath(points: Array<[number, number]>, options: { closed?: boolean; fill?: string; fillOpacity?: number; opacity?: number } = {}) {
|
||
|
|
const path = new THREE.ShapePath();
|
||
|
|
path.moveTo(points[0][0], points[0][1]);
|
||
|
|
for (const [x, y] of points.slice(1)) path.lineTo(x, y);
|
||
|
|
if (options.closed !== false) path.currentPath!.autoClose = true;
|
||
|
|
(path as THREE.ShapePath & { userData: unknown }).userData = {
|
||
|
|
style: {
|
||
|
|
fill: options.fill ?? "#000",
|
||
|
|
fillOpacity: options.fillOpacity ?? 1,
|
||
|
|
opacity: options.opacity ?? 1,
|
||
|
|
visibility: "visible",
|
||
|
|
},
|
||
|
|
};
|
||
|
|
return path;
|
||
|
|
}
|
||
|
|
|
||
|
|
function rectangle(x: number, y: number, width: number, height: number, options?: Parameters<typeof shapePath>[1]) {
|
||
|
|
return shapePath(
|
||
|
|
[
|
||
|
|
[x, y],
|
||
|
|
[x + width, y],
|
||
|
|
[x + width, y + height],
|
||
|
|
[x, y + height],
|
||
|
|
],
|
||
|
|
options,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
function geometryPositions(geometry: THREE.BufferGeometry) {
|
||
|
|
const nonIndexed = geometry.index ? geometry.toNonIndexed() : geometry;
|
||
|
|
const attribute = nonIndexed.getAttribute("position");
|
||
|
|
const positions: number[] = [];
|
||
|
|
for (let index = 0; index < attribute.count; index += 1) {
|
||
|
|
positions.push(attribute.getX(index), attribute.getY(index), attribute.getZ(index));
|
||
|
|
}
|
||
|
|
if (nonIndexed !== geometry) nonIndexed.dispose();
|
||
|
|
geometry.dispose();
|
||
|
|
return positions;
|
||
|
|
}
|
||
|
|
|
||
|
|
describe("SVG source preflight", () => {
|
||
|
|
it("rejects XML entities and external references", () => {
|
||
|
|
expect(() => validateSvgSourcePreflight('<!DOCTYPE svg [<!ENTITY x "bad">]><svg/>')).toThrow(/document types and entities/i);
|
||
|
|
expect(() => validateSvgSourcePreflight('<svg><use href="https://example.com/art.svg#part"/></svg>')).toThrow(/external references/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("rejects excessive geometry before SVGLoader runs", () => {
|
||
|
|
const source = `<svg>${"<rect width='1' height='1'/>".repeat(MAX_SVG_GEOMETRY_ELEMENTS + 1)}</svg>`;
|
||
|
|
expect(() => validateSvgSourcePreflight(source)).toThrow(/too many geometry elements/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("normalizes modern local use href attributes for SVGLoader", () => {
|
||
|
|
const normalized = normalizeSvgUseReferences('<svg><defs><path id="p" d="M0 0L1 0L1 1Z"/></defs><use href="#p"/></svg>');
|
||
|
|
expect(normalized).toContain('xmlns:xlink="http://www.w3.org/1999/xlink"');
|
||
|
|
expect(normalized).toContain('xlink:href="#p"');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("SVG path extrusion", () => {
|
||
|
|
it("creates a watertight solid with real, unclamped dimensions", () => {
|
||
|
|
const result = buildSvgExtrusionFromPaths([rectangle(0, 0, 0.25, 0.5)]);
|
||
|
|
expect(result.analysis.width).toBeCloseTo(0.25);
|
||
|
|
expect(result.analysis.height).toBeCloseTo(4);
|
||
|
|
expect(result.analysis.depth).toBeCloseTo(0.5);
|
||
|
|
expect(result.analysis.volume).toBeCloseTo(0.5);
|
||
|
|
expect(result.analysis.boundaryEdges).toBe(0);
|
||
|
|
expect(result.analysis.nonManifoldEdges).toBe(0);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("treats a separately defined contained contour as a hole", () => {
|
||
|
|
const result = buildSvgExtrusionFromPaths([rectangle(0, 0, 10, 10), rectangle(3, 3, 4, 4)]);
|
||
|
|
expect(result.analysis.volume).toBeCloseTo((100 - 16) * 4, 5);
|
||
|
|
expect(result.analysis.boundaryEdges).toBe(0);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("ignores non-filled and fully transparent paths", () => {
|
||
|
|
expect(() => buildSvgExtrusionFromPaths([rectangle(0, 0, 10, 10, { fill: "none" })])).toThrow(/no readable visible filled paths/i);
|
||
|
|
expect(() => buildSvgExtrusionFromPaths([rectangle(0, 0, 10, 10, { opacity: 0 })])).toThrow(/no readable visible filled paths/i);
|
||
|
|
expect(() => buildSvgExtrusionFromPaths([rectangle(0, 0, 10, 10, { fillOpacity: 0 })])).toThrow(/no readable visible filled paths/i);
|
||
|
|
expect(() => buildSvgExtrusionFromPaths([rectangle(0, 0, 10, 10, { fill: "#00000000" })])).toThrow(/no readable visible filled paths/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("imports open filled contours when they enclose usable area and skips lines", () => {
|
||
|
|
const result = buildSvgExtrusionFromPaths([shapePath([[0, 0], [10, 0], [5, 5]], { closed: false })]);
|
||
|
|
expect(result.analysis.volume).toBeCloseTo(100);
|
||
|
|
expect(() => buildSvgExtrusionFromPaths([shapePath([[0, 0], [10, 0]], { closed: false })])).toThrow(/no (?:readable )?filled (?:paths|contours)/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("skips closed collinear paths", () => {
|
||
|
|
expect(() => buildSvgExtrusionFromPaths([shapePath([[0, 0], [5, 0], [10, 0]])])).toThrow(/no readable filled paths/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("imports overlapping contours as separate valid components", () => {
|
||
|
|
const result = buildSvgExtrusionFromPaths([rectangle(0, 0, 10, 10), rectangle(5, 5, 10, 10)]);
|
||
|
|
expect(result.analysis.volume).toBeCloseTo(800);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("triangle-soup solid validation", () => {
|
||
|
|
it("accepts a closed box", () => {
|
||
|
|
const positions = geometryPositions(new THREE.BoxGeometry(2, 3, 4));
|
||
|
|
const analysis = validateClosedSolidTriangleSoup(positions);
|
||
|
|
expect(analysis.volume).toBeCloseTo(24);
|
||
|
|
expect(analysis.boundaryEdges).toBe(0);
|
||
|
|
expect(analysis.nonManifoldEdges).toBe(0);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("rejects an open box shell", () => {
|
||
|
|
const positions = geometryPositions(new THREE.BoxGeometry(2, 3, 4)).slice(9);
|
||
|
|
expect(analyzeTriangleSoup(positions).boundaryEdges).toBeGreaterThan(0);
|
||
|
|
expect(() => validateClosedSolidTriangleSoup(positions)).toThrow(/not a watertight manifold/i);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("rejects a topologically closed zero-volume shell", () => {
|
||
|
|
const positions = [
|
||
|
|
0, 0, 0, 1, 0, 0, 0, 1, 0,
|
||
|
|
0, 0, 0, 0, 1, 0, 1, 0, 0,
|
||
|
|
];
|
||
|
|
const analysis = analyzeTriangleSoup(positions);
|
||
|
|
expect(analysis.boundaryEdges).toBe(0);
|
||
|
|
expect(analysis.volume).toBe(0);
|
||
|
|
expect(() => validateClosedSolidTriangleSoup(positions)).toThrow(/non-zero volume/i);
|
||
|
|
});
|
||
|
|
});
|