Files
Enes Yakıştır e7b6db9db6
CI / Typecheck and unit tests (push) Canceled after 0s
Build and Push Docker Images / build (push) Canceled after 0s
feat: sesli CAD asistani, bellek optimizasyonlari ve akilli cozunurluk
- SnapVoice Turkce sesli CAD ve komut konsolu (/denetle, /ram, /eko, /otomatik, /sessiz)
- 3B uzamsal sesli radar ve gorme engelli gelistirici geometri denetim motoru
- LibreDWG/DXF ikili sikistirma, font tembel yukleme ve RAM optimizasyonu
- Monitor cozunurlugune gore otomatik uyarlamali dinamik grafik modu
2026-11-02 13:37:37 +03:00

141 lines
4.9 KiB
TypeScript

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import {
audit3DScene,
audit2DDrawing,
parseDxfToCustomCadEntities,
fitEntitiesToDrawingCanvas,
type CustomCadEntity,
} from "@/lib/cadAuditor";
import type { WorkplaneShape } from "@/types/sketchforge";
describe("CAD Auditor - 3D Scene Inspection", () => {
it("returns clear empty report when scene has no shapes", () => {
const report = audit3DScene([]);
expect(report.totalShapes).toBe(0);
expect(report.solidCount).toBe(0);
expect(report.holeCount).toBe(0);
expect(report.speechSummary).toContain("Çalışma düzlemi boş");
});
it("calculates accurate bounding box, counts, and volume for solid and hole shapes", () => {
const shapes: WorkplaneShape[] = [
{
id: "box1",
name: "Plaka Gövde",
kind: "box",
x: 0,
z: 0,
elevation: 0,
width: 100,
depth: 60,
height: 20,
hole: false,
color: "#0ea5e9",
},
{
id: "hole1",
name: "Montaj Deliği",
kind: "cylinder",
x: 0,
z: 0,
elevation: -2,
width: 16,
depth: 16,
height: 24,
hole: true,
color: "#f43f5e",
},
];
const report = audit3DScene(shapes);
expect(report.totalShapes).toBe(2);
expect(report.solidCount).toBe(1);
expect(report.holeCount).toBe(1);
expect(report.boundingBox.width).toBe(100);
expect(report.boundingBox.depth).toBe(60);
expect(report.boundingBox.height).toBe(24);
expect(report.netEstimatedVolumeCm3).toBeGreaterThan(110);
expect(report.netEstimatedVolumeCm3).toBeLessThan(125);
expect(report.overlappingPairs.length).toBe(1);
expect(report.overlappingPairs[0].reason).toContain("Montaj Deliği");
expect(report.speechSummary).toContain("3B Sahnede 2 nesne var");
expect(report.fullTextReport).toContain("SNAPCAD 3B SAHNE DENETİM RAPORU");
});
});
describe("CAD Auditor - 2D Drawing Inspection", () => {
it("returns empty report when pafta has no entities", () => {
const report = audit2DDrawing([]);
expect(report.totalEntities).toBe(0);
expect(report.speechSummary).toContain("Teknik resim paftasında henüz kullanıcı çizimi bulunmuyor");
});
it("analyzes closed loops, entity counts, layers, and open endpoints", () => {
const entities: CustomCadEntity[] = [
{ id: "1", type: "line", x1: 0, y1: 0, x2: 100, y2: 0, layer: "VISIBLE" },
{ id: "2", type: "line", x1: 100, y1: 0, x2: 100, y2: 50, layer: "VISIBLE" },
{ id: "3", type: "line", x1: 100, y1: 50, x2: 0, y2: 50, layer: "VISIBLE" },
{ id: "4", type: "line", x1: 0, y1: 50, x2: 0, y2: 0, layer: "VISIBLE" },
{ id: "5", type: "circle", x1: 50, y1: 25, radius: 10, layer: "CENTER" },
{ id: "6", type: "dim", x1: 0, y1: 0, x2: 100, y2: 0, label: "100 mm", layer: "DIMENSION" },
];
const report = audit2DDrawing(entities);
expect(report.totalEntities).toBe(6);
expect(report.countsByType.line).toBe(4);
expect(report.countsByType.circle).toBe(1);
expect(report.countsByType.dim).toBe(1);
expect(report.countsByLayer.VISIBLE).toBe(4);
expect(report.countsByLayer.CENTER).toBe(1);
expect(report.countsByLayer.DIMENSION).toBe(1);
expect(report.openEndpointsCount).toBe(0); // All 4 line vertices form a continuous closed loop
expect(report.speechSummary).toContain("6 geometrik eleman var");
});
});
describe("Technical Drawing Studio - DXF Entity Parser & Canvas Fitting", () => {
it("parses ASCII DXF text into CustomCadEntity list with layer mappings", () => {
const sampleDxf = [
"0", "SECTION",
"2", "ENTITIES",
"0", "LINE",
"8", "CENTER_LINES",
"10", "10.0",
"20", "20.0",
"11", "50.0",
"21", "20.0",
"0", "CIRCLE",
"8", "VISIBLE_OUTLINE",
"10", "30.0",
"20", "20.0",
"40", "15.0",
"0", "ENDSEC",
"0", "EOF",
].join("\n");
const parsed = parseDxfToCustomCadEntities(sampleDxf);
expect(parsed.length).toBe(2);
expect(parsed[0].type).toBe("line");
expect(parsed[0].layer).toBe("CENTER");
expect(parsed[0].x1).toBe(10);
expect(parsed[0].x2).toBe(50);
expect(parsed[1].type).toBe("circle");
expect(parsed[1].layer).toBe("VISIBLE");
expect(parsed[1].radius).toBe(15);
});
it("scales and centers distant CAD entities to fit within the 2D pafta drawing sheet", () => {
const distantEntities: CustomCadEntity[] = [
{ id: "1", type: "line", x1: 10000, y1: 50000, x2: 15000, y2: 50000, layer: "VISIBLE" },
{ id: "2", type: "circle", x1: 12500, y1: 52000, radius: 500, layer: "VISIBLE" },
];
const fitted = fitEntitiesToDrawingCanvas(distantEntities, 400, 300);
expect(fitted.length).toBe(2);
expect(fitted[0].x1).toBeGreaterThanOrEqual(100);
expect(fitted[0].x1).toBeLessThanOrEqual(600);
expect(fitted[0].y1).toBeGreaterThanOrEqual(100);
expect(fitted[0].y1).toBeLessThanOrEqual(500);
});
});