Files
snapcad-studio/tests/unit/offsetKernel.test.ts
T
Enes Yakıştır 33b0940012
Build and Push Docker Images / build (push) Canceled after 0s
CI / Typecheck and unit tests (push) Canceled after 0s
feat: SnapCAD Studio'yu YakHub deposuna taşı
- DWG/DXF içe aktarma ve .skf yeniden açma düzeltmeleri

- YakNet Bulut eşitlemede boş/eski kopya koruması ve yerel-only proje bildirimi

- Panelden içe aktarma duyuruları ve erişilebilir Türkçe hata mesajları

- AGPL-3.0 lisansı, README ve YakHub bağlantıları
2026-10-25 18:20:21 +03:00

75 lines
2.5 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, it, expect } from "vitest";
import { offsetPolygon, polygonSignedArea, offsetSketchProfile, type Point2D } from "@/lib/offsetKernel";
describe("Offset Tool Kernel (Ofset Aracı & Duvar Kalınlığı)", () => {
it("calculates signed area of a rectangle correctly", () => {
// 100 x 50 rectangle (CCW)
const rect: Point2D[] = [
{ x: 0, z: 0 },
{ x: 100, z: 0 },
{ x: 100, z: 50 },
{ x: 0, z: 50 },
];
const area = polygonSignedArea(rect);
expect(area).toBe(5000);
});
it("offsets a rectangle outward by 10mm", () => {
const rect: Point2D[] = [
{ x: 0, z: 0 },
{ x: 100, z: 0 },
{ x: 100, z: 50 },
{ x: 0, z: 50 },
];
const outset = offsetPolygon(rect, 10);
expect(outset.length).toBe(4);
// Outward expands by 10 on all sides: width becomes 120, height becomes 70
const minX = Math.min(...outset.map((p) => p.x));
const maxX = Math.max(...outset.map((p) => p.x));
const minZ = Math.min(...outset.map((p) => p.z));
const maxZ = Math.max(...outset.map((p) => p.z));
expect(Math.round(maxX - minX)).toBe(120);
expect(Math.round(maxZ - minZ)).toBe(70);
});
it("offsets a room perimeter inward by 15mm to generate interior wall", () => {
const room: Point2D[] = [
{ x: 0, z: 0 },
{ x: 200, z: 0 },
{ x: 200, z: 150 },
{ x: 0, z: 150 },
];
// Inset by -15mm
const inset = offsetPolygon(room, -15);
expect(inset.length).toBe(4);
const minX = Math.min(...inset.map((p) => p.x));
const maxX = Math.max(...inset.map((p) => p.x));
const minZ = Math.min(...inset.map((p) => p.z));
const maxZ = Math.max(...inset.map((p) => p.z));
expect(Math.round(maxX - minX)).toBe(170); // 200 - 30 = 170
expect(Math.round(maxZ - minZ)).toBe(120); // 150 - 30 = 120
});
it("offsets a SketchProfile into a dual-walled footprint", () => {
const initialProfile = {
points: [
{ id: "p1", x: 0, z: 0 },
{ id: "p2", x: 100, z: 0 },
{ id: "p3", x: 100, z: 80 },
{ id: "p4", x: 0, z: 80 },
],
segments: [
{ id: "s1", startId: "p1", endId: "p2" },
{ id: "s2", startId: "p2", endId: "p3" },
{ id: "s3", startId: "p3", endId: "p4" },
{ id: "s4", startId: "p4", endId: "p1" },
],
};
const walledProfile = offsetSketchProfile(initialProfile, -10);
expect(walledProfile.points.length).toBe(8); // 4 outer + 4 inner wall points
expect(walledProfile.segments.length).toBe(8); // 4 outer + 4 inner segments
});
});