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
feat: improve modeling, exports, and hosted deployment
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { GET, POST } from "@/app/api/project-thumbnail/route";
|
||||
|
||||
function missingThumbnailRequest(url: string, headers?: HeadersInit) {
|
||||
return new Request(`${url}/api/project-thumbnail?projectId=missing-thumbnail`, { headers });
|
||||
}
|
||||
|
||||
describe("project thumbnail request origins", () => {
|
||||
it("allows same-origin requests on a public HTTPS host", async () => {
|
||||
const response = await GET(missingThumbnailRequest("https://projects.example.test", {
|
||||
Origin: "https://projects.example.test",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
}));
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("uses forwarded host and protocol behind a TLS reverse proxy", async () => {
|
||||
const response = await GET(missingThumbnailRequest("http://localhost:3000", {
|
||||
Origin: "https://projects.example.test",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
"X-Forwarded-Host": "projects.example.test",
|
||||
"X-Forwarded-Proto": "https",
|
||||
}));
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("rejects a different origin", async () => {
|
||||
const response = await GET(missingThumbnailRequest("https://projects.example.test", {
|
||||
Origin: "https://other.example.test",
|
||||
"Sec-Fetch-Site": "cross-site",
|
||||
}));
|
||||
|
||||
expect(response.status).toBe(403);
|
||||
});
|
||||
|
||||
it("allows same-origin uploads to proceed to request validation", async () => {
|
||||
const response = await POST(new Request("https://projects.example.test/api/project-thumbnail", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Origin: "https://projects.example.test",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
},
|
||||
body: JSON.stringify({}),
|
||||
}));
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
await expect(response.json()).resolves.toEqual({ error: "Invalid thumbnail request" });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { addLineIntersectionPoints, closestPointOnSketchSegment, splitSketchSegment } from "@/lib/sketchPointRefinement";
|
||||
import type { SketchProfile } from "@/types/sketchforge";
|
||||
|
||||
function idFactory() {
|
||||
let value = 0;
|
||||
return (prefix: string) => `${prefix}-${++value}`;
|
||||
}
|
||||
|
||||
describe("sketch point refinement", () => {
|
||||
it("projects the refine preview onto the exact line position", () => {
|
||||
const start = { id: "a", x: 0, z: 0 };
|
||||
const end = { id: "b", x: 10, z: 0 };
|
||||
const placement = closestPointOnSketchSegment(
|
||||
{ id: "line", startId: "a", endId: "b", kind: "line" },
|
||||
start,
|
||||
end,
|
||||
{ x: 3, z: 4 },
|
||||
);
|
||||
expect(placement.amount).toBeCloseTo(0.3, 8);
|
||||
expect(placement.point).toEqual({ x: 3, z: 0 });
|
||||
});
|
||||
|
||||
it("splits a bezier without moving the curve at the inserted point", () => {
|
||||
const profile: SketchProfile = {
|
||||
points: [
|
||||
{ id: "a", x: 0, z: 0, handleOut: { x: 0, z: 10 }, mode: "smooth" },
|
||||
{ id: "b", x: 10, z: 0, handleIn: { x: 10, z: 10 }, mode: "smooth" },
|
||||
],
|
||||
segments: [{ id: "curve", startId: "a", endId: "b", kind: "bezier" }],
|
||||
};
|
||||
const result = splitSketchSegment(profile, "curve", 0.5, idFactory());
|
||||
expect(result.inserted).toBe(true);
|
||||
const inserted = result.profile.points.find((point) => point.id === result.pointId);
|
||||
expect(inserted?.x).toBeCloseTo(5, 8);
|
||||
expect(inserted?.z).toBeCloseTo(7.5, 8);
|
||||
expect(inserted?.handleIn).toEqual({ x: 2.5, z: 7.5 });
|
||||
expect(inserted?.handleOut).toEqual({ x: 7.5, z: 7.5 });
|
||||
expect(result.profile.segments).toHaveLength(2);
|
||||
expect(result.profile.segments[0].endId).toBe(result.pointId);
|
||||
expect(result.profile.segments[1].startId).toBe(result.pointId);
|
||||
});
|
||||
|
||||
it("adds one shared point and splits both crossing lines", () => {
|
||||
const profile: SketchProfile = {
|
||||
points: [
|
||||
{ id: "a", x: 0, z: 0 },
|
||||
{ id: "b", x: 10, z: 10 },
|
||||
{ id: "c", x: 0, z: 10 },
|
||||
{ id: "d", x: 10, z: 0 },
|
||||
],
|
||||
segments: [
|
||||
{ id: "first", startId: "a", endId: "b", kind: "line" },
|
||||
{ id: "second", startId: "c", endId: "d", kind: "line" },
|
||||
],
|
||||
};
|
||||
const next = addLineIntersectionPoints(profile, idFactory());
|
||||
const intersection = next.points.find((point) => Math.abs(point.x - 5) < 1e-8 && Math.abs(point.z - 5) < 1e-8);
|
||||
expect(intersection).toBeTruthy();
|
||||
expect(next.points).toHaveLength(5);
|
||||
expect(next.segments).toHaveLength(4);
|
||||
expect(next.segments.filter((segment) => segment.startId === intersection?.id || segment.endId === intersection?.id)).toHaveLength(4);
|
||||
});
|
||||
|
||||
it("reuses an existing endpoint when it lands on the middle of another line", () => {
|
||||
const profile: SketchProfile = {
|
||||
points: [
|
||||
{ id: "a", x: 0, z: 0 },
|
||||
{ id: "b", x: 10, z: 0 },
|
||||
{ id: "touch", x: 5, z: 0 },
|
||||
{ id: "d", x: 5, z: 6 },
|
||||
],
|
||||
segments: [
|
||||
{ id: "horizontal", startId: "a", endId: "b", kind: "line" },
|
||||
{ id: "vertical", startId: "touch", endId: "d", kind: "line" },
|
||||
],
|
||||
};
|
||||
const next = addLineIntersectionPoints(profile, idFactory());
|
||||
expect(next.points).toHaveLength(4);
|
||||
expect(next.segments).toHaveLength(3);
|
||||
expect(next.segments.filter((segment) => segment.startId === "touch" || segment.endId === "touch")).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("does not invent points for collinear overlap", () => {
|
||||
const profile: SketchProfile = {
|
||||
points: [
|
||||
{ id: "a", x: 0, z: 0 },
|
||||
{ id: "b", x: 10, z: 0 },
|
||||
{ id: "c", x: 5, z: 0 },
|
||||
{ id: "d", x: 15, z: 0 },
|
||||
],
|
||||
segments: [
|
||||
{ id: "first", startId: "a", endId: "b", kind: "line" },
|
||||
{ id: "second", startId: "c", endId: "d", kind: "line" },
|
||||
],
|
||||
};
|
||||
expect(addLineIntersectionPoints(profile, idFactory())).toBe(profile);
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,52 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { exportMeshesToStl } from "@/lib/stlExport";
|
||||
|
||||
describe("STL export orientation", () => {
|
||||
it("writes editor Y-up coordinates as slicer Z-up coordinates", () => {
|
||||
function readPoint(view: DataView, offset: number) {
|
||||
return [
|
||||
view.getFloat32(offset, true),
|
||||
view.getFloat32(offset + 4, true),
|
||||
view.getFloat32(offset + 8, true),
|
||||
];
|
||||
}
|
||||
|
||||
describe("binary STL export", () => {
|
||||
it("uses the fixed binary STL record size and triangle count", () => {
|
||||
const stl = exportMeshesToStl([
|
||||
{
|
||||
vertices: [[0, 0, 0], [1, 0, 0], [0, 1, 0]],
|
||||
faces: [[0, 1, 2]],
|
||||
},
|
||||
{
|
||||
vertices: [[0, 0, 0], [0, 1, 0], [0, 0, 1]],
|
||||
faces: [[0, 1, 2]],
|
||||
},
|
||||
]);
|
||||
const view = new DataView(stl);
|
||||
|
||||
expect(stl.byteLength).toBe(84 + 2 * 50);
|
||||
expect(view.getUint32(80, true)).toBe(2);
|
||||
});
|
||||
|
||||
it("writes editor Y-up coordinates as slicer Z-up float32 values", () => {
|
||||
const stl = exportMeshesToStl([{
|
||||
vertices: [[0, 0, 0], [10, 0, 0], [0, 20, 5]],
|
||||
faces: [[0, 1, 2]],
|
||||
}]);
|
||||
const view = new DataView(stl);
|
||||
|
||||
expect(stl).toContain("vertex 0 -5 20");
|
||||
expect(readPoint(view, 84 + 12 + 2 * 12)).toEqual([0, -5, 20]);
|
||||
});
|
||||
|
||||
it("writes a unit facet normal and clears the attribute byte count", () => {
|
||||
const stl = exportMeshesToStl([{
|
||||
vertices: [[0, 0, 0], [10, 0, 0], [0, 20, 5]],
|
||||
faces: [[0, 1, 2]],
|
||||
}]);
|
||||
const view = new DataView(stl);
|
||||
const normal = readPoint(view, 84);
|
||||
|
||||
expect(Math.hypot(...normal)).toBeCloseTo(1);
|
||||
expect(normal).toEqual([0, expect.closeTo(-0.9701425), expect.closeTo(-0.2425356)]);
|
||||
expect(view.getUint16(84 + 48, true)).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,10 @@ import {
|
||||
resizedShapeSize,
|
||||
serializeShapesForSync,
|
||||
shapeDepth,
|
||||
shapeHasTaper,
|
||||
shapeOverallFootprintDimensions,
|
||||
shapeTaperDimensions,
|
||||
shapeTaperScaleAt,
|
||||
shapeWidth,
|
||||
withHoleMode,
|
||||
workplaneShapesEqual,
|
||||
@@ -78,6 +82,32 @@ describe("workplane shape helpers", () => {
|
||||
expect(proportionalResizeScale(50, 100, 25, 80)).toBe(0.5);
|
||||
});
|
||||
|
||||
it("interpolates actual top and bottom taper dimensions while excluding gears", () => {
|
||||
const tapered = shape({
|
||||
taperBottomWidth: 10,
|
||||
taperBottomDepth: 5,
|
||||
taperTopWidth: 30,
|
||||
taperTopDepth: 40,
|
||||
});
|
||||
expect(shapeTaperDimensions(tapered)).toEqual({ topWidth: 30, topDepth: 40, bottomWidth: 10, bottomDepth: 5 });
|
||||
expect(shapeOverallFootprintDimensions(tapered)).toEqual({ width: 30, depth: 40 });
|
||||
expect(shapeHasTaper(tapered)).toBe(true);
|
||||
expect(shapeTaperScaleAt(tapered, 0, "width")).toBe(0.5);
|
||||
expect(shapeTaperScaleAt(tapered, 0.5, "width")).toBe(1);
|
||||
expect(shapeTaperScaleAt(tapered, 1, "width")).toBe(1.5);
|
||||
expect(shapeTaperScaleAt(tapered, 0, "depth")).toBe(0.25);
|
||||
expect(shapeTaperScaleAt(tapered, 0.5, "depth")).toBe(1.125);
|
||||
expect(shapeTaperScaleAt(tapered, 1, "depth")).toBe(2);
|
||||
|
||||
const legacy = shape({ taperBottomScale: 0.5, taperTopScale: 1.5 });
|
||||
expect(shapeTaperDimensions(legacy)).toEqual({ topWidth: 30, topDepth: 30, bottomWidth: 10, bottomDepth: 10 });
|
||||
|
||||
const gear = shape({ kind: "gear", taperBottomWidth: 10, taperTopWidth: 30 });
|
||||
expect(shapeHasTaper(gear)).toBe(false);
|
||||
expect(shapeTaperScaleAt(gear, 0.5, "width")).toBe(1);
|
||||
expect(shapeTaperScaleAt(gear, 0.5, "depth")).toBe(1);
|
||||
});
|
||||
|
||||
it("canonicalizes mirror flags and nested group rotations", () => {
|
||||
const canonical = canonicalizeShape(
|
||||
shape({
|
||||
|
||||
Reference in New Issue
Block a user