Files
snapcad-studio/tests/unit/smartPlacement.test.ts
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

90 lines
2.3 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 {
calculateSmartPlacementPoint,
calculateTopSurfaceElevation,
} from "@/lib/smartPlacement";
import type { WorkplaneShape } from "@/types/sketchforge";
describe("Smart Placement & Anti-Collision (Akıllı Yerleşim ve Çakışma Önleme)", () => {
it("places at origin when scene is empty", () => {
const point = calculateSmartPlacementPoint([], { width: 20, depth: 20 });
expect(point.x).toBe(0);
expect(point.z).toBe(0);
});
it("places cleanly beside an existing house centered at (0, 0)", () => {
// Miniature house centered at (0, 0), width 80, depth 60
const house: WorkplaneShape = {
id: "house-1",
name: "Minyatür Ev",
kind: "box",
color: "#f59e0b",
x: 0,
z: 0,
width: 80,
depth: 60,
height: 50,
elevation: 0,
rotation: 0,
};
// New 20x20 cube added
const point = calculateSmartPlacementPoint([house], { width: 20, depth: 20 });
// House extends from X = -40 to +40.
// New cube should be placed to the right: 40 + 10 (half width) + 12 (margin) = 62
expect(point.x).toBe(62);
expect(point.z).toBe(0);
});
it("calculates top surface elevation to pop an interior cube onto the roof", () => {
const houseBody: WorkplaneShape = {
id: "house-body",
name: "Ev Gövdesi",
kind: "box",
color: "#f59e0b",
x: 0,
z: 0,
width: 60,
depth: 60,
height: 40,
elevation: 0,
rotation: 0,
};
const roof: WorkplaneShape = {
id: "house-roof",
name: "Çatı",
kind: "roof",
color: "#dc2626",
x: 0,
z: 0,
width: 64,
depth: 64,
height: 25,
elevation: 40, // sits on top of body (40 + 25 = 65)
rotation: 0,
};
// Cube swallowed inside at (0, 0, 0)
const swallowedCube: WorkplaneShape = {
id: "cube-inside",
name: "Kutu",
kind: "box",
color: "#3b82f6",
x: 0,
z: 0,
width: 20,
depth: 20,
height: 20,
elevation: 0,
rotation: 0,
};
const topElevation = calculateTopSurfaceElevation(swallowedCube, [houseBody, roof, swallowedCube]);
// Top of the roof is 40 + 25 = 65mm
expect(topElevation).toBe(65);
});
});