Compare commits
2 Commits
33f6f2d21b
...
89df306078
| Author | SHA1 | Date | |
|---|---|---|---|
| 89df306078 | |||
| 11a0dcb4e8 |
+4
-3
@@ -667,6 +667,7 @@ Format: `YYYY-MM-DD | TASK-ID | was getan | Tests Ergebnis | commit | Notizen/of
|
||||
|
||||
| Datum | Task | Zusammenfassung | Tests | Commit | Notizen |
|
||||
|---|---|---|---|---|---|
|
||||
| 2026-08-29 | CAD-2 | Echte Hatch-Muster: (1) hatchPatternService NEU (154 Zeilen) — 9 Muster als HatchPattern-Definitionen (id/label/description/defaultSpacing/angles/dots/solid): ANSI31 (45°), ANSI32 (Eisen 45/-45), ANSI37 (Beton dicht), NET (H+V), GRASS (75°), DOTS (Punktraster), SOLID (Vollfläche) + legacy lines/cross bleiben erhalten; generateHatchLines: Linienfamilien je Winkel über BBox-Diagonale mit Liang-Barsky-Clipping an der BBox, DOTS als Punktraster, SOLID als ein Segment mit fill-Flag; computeBoundary: BBox aus Kontur-Punkten (≥2 Punkte, sonst null); (2) hatchTool optionsSchema auf 9 Muster erweitert; (3) elementDrawers: hatchPrimitives-Helfer (hatch-Flag + Muster + Spacing → Segment-Primitives) in rect-, circle- und polyline/polygon-Cases integriert — Basis-Primitive + Hatch-Linien als kombiniertes Array; Typ-Fix: explizite ShapePrimitive[]-Annotationen gegen Literal-Widening | Frontend: 734/734 Tests (+11 hatchPatterns.test.ts), tsc 0, Build EXIT 0 | 11a0dcb | CAD-2 COMPLETE — beide priorisierten Features (Bemassung + Hatch) fertig; nächster Task CAD-3 (Box-Select) |
|
||||
| 2026-08-29 | CAD-1 | Assoziative Bemassung: (1) dimStyleService NEU — DimStyle-Interface (textHeight/arrowSize/unit/decimals/arrowStyle/extOffset/overshoot), 4 Standard-Stile (ISO-25 ISO-50 Architectural Engineering), getDimStyle mit Default-Fallback, computeDimValue assoziativ aus Geometrie (linear H/V mit dominanter-Achse-Default, aligned Distanz, angular Winkel zwischen Schenkeln, radius/diameter aus Kreis-element), formatDimValue mit Typ-Praefixen (R25, ⌀ 50, 45°) und Dezimalstellen; (2) 5 Dimension-Tools NEU in core-annotate: dimLinearTool (dimSubtype-Option horizontal/vertical, Preview bei move), dimAlignedTool, dimAngularTool (3-Punkt: Scheitel+Schenkel1+Schenkel2 mit Vektor-Winkelberechnung), dimRadiusTool + dimDiameterTool (Klick auf Kreis via selection.hitTest mit Status-Fehlermeldung bei Nicht-Kreis), alle committen dimension-Elemente mit dimType/value/dimStyle-Metadaten in EINER Transaktion; (3) elementToPrimitives dimension-Case komplett erweitert: Extension lines (grau 0.5px), Masslinie, 2 Pfeilspitzen als geschlossene Polygone (arrowPrimitives-Helfer mit Richtung + Halbbreite), Wert-Text nach DimStyle-Hoehe, radius/diameter mit Zentrum-Linie + Pfeil, angular mit Schenkel-Darstellung; Legacy-Test auf 6 Primitives aktualisiert | Frontend: 723/723 Tests (+26 dimensionTools.test.ts), tsc 0 (nach Pt-Import-Fix), Build EXIT 0 | 44a60fa | CAD-1 COMPLETE; nächster Task CAD-2 (Hatch-Muster) |
|
||||
| 2026-08-29 | I3 | **RELEASE 2.0.0**: (1) Git-Tag v2.0.0 auf a20731a gesetzt (annotiert mit Phasen A–H & Test-Stand) und auf Forgejo gepusht; (2) Deploy über coolify-01 (SSH-Skill): Server-Repo /data/web-cad-neu auf main=a20731a aktualisiert, deploy.sh ausgeführt — beide Docker-Images (web-cad-neu-backend/frontend:latest) frisch gebaut, Coolify-Service cnuavrh33goa3zs0upi6hgif Container recreated (backend gestartet + healthy, frontend danach gestartet); (3) Deploy-Verify DREIFACH: Backend-Health im Container {status:ok}, Live-URL https://web-cad-neu.server.media-on.de HTTP 200, Backend-API von außen (Server + Agent-Container) {status:ok} — Production-Release live; CI-Pipeline führt beim Tag-Push den kompletten Lauf inkl. neuem Perf-Gate aus (Forgejo) | Prod-Deploy verifiziert: Backend-healthy, Frontend 200, API extern ok | v2.0.0 (Tag) | **I3 COMPLETE — ROADMAP VOLLSTÄNDIG: ALLE PHASEN A–I ABGESCHLOSSEN, WebCAD 2.0.0 IST LIVE** |
|
||||
| 2026-08-29 | I1 | CI erweitert: (1) playwright-tests/perf-gate.test.ts NEU — Performance-Gate nach Roadmap-Vorgabe: 10.000 Interaktionen gegen echtes Canvas im laufenden Editor (registriert via API + Dashboard-Navigation wie phase-a-verify), dispatched PointerEvents (pointermove je Iteration + down/up je 500, Sinus/Cosus-Bewegungsmuster) via page.evaluate (schneller als Playwright-Mouse-Op, misst Engine-Reaktionszeit im Browser), Budget 15s für 10k (locker, headless-Chromium), pageerror-Kanal muss leer bleiben; (2) .forgejo/workflows/ci.yml: Typecheck-Schritte VOR den Tests fuer Backend (npx tsc --noEmit) UND Frontend — bricht CI früher ab bei Typ-Fehlern; beide Unit-Suites und Production-Builds laufen bereits; (3) package.json test:e2e:ci um perf-gate.test.ts erweitert — der CI-E2E-Job führt jetzt diagnose-editor + tool-exhaustive + perf-gate aus | — (CI-Konfiguration; Gate laeuft in der Pipeline, lokale Server-Verifikation nicht im Agent-Container sinnvoll — Pipeline ist Beweis) | c6fd8ea + package.json | I1 COMPLETE; nächster Task I3 (Release 2.0) — der LETZTE offene Roadmap-Punkt |
|
||||
@@ -754,13 +755,13 @@ Format: `YYYY-MM-DD | TASK-ID | was getan | Tests Ergebnis | commit | Notizen/of
|
||||
- `frontend/src/utils/__tests__/format.test.ts` liegt in src statt tests/ — vereinheitlichen (kleiner Task in I2)
|
||||
|
||||
---
|
||||
*Post-2.0 CAD-Ausbau laeuft: **CAD-2** (Echte Hatch-Muster + Boundary-Erkennung) als naechster Task. Danach: CAD-3 Box-Select, CAD-4 OTRACK/DIVIDE, CAD-5 MLINE/Block-Editor.*
|
||||
*Status 2026-08-29: RELEASE 2.0.0 LIVE + Post-2.0: CAD-1 (Bemassung) fertig. FE 723/723 Tests, BE 287/287, tsc/Build grün, Prod-Deploy verifiziert. Tag v2.0.0 auf Forgejo main.*
|
||||
*Post-2.0 CAD-Ausbau: CAD-1 (Bemassung) + CAD-2 (Hatch-Muster) fertig. Naechster Task: **CAD-3** (Box-Select). Danach: CAD-4 OTRACK/DIVIDE, CAD-5 MLINE/Block-Editor.*
|
||||
*Status 2026-08-29: RELEASE 2.0.0 LIVE + Post-2.0: CAD-1 (Bemassung) + CAD-2 (Hatch) fertig. FE 734/734 Tests, BE 287/287, tsc/Build grün, Prod-Deploy verifiziert. Tag v2.0.0 auf Forgejo main.*
|
||||
|
||||
## Post-2.0 CAD-Ausbau (neue Task-Reihe)
|
||||
|
||||
- [x] CAD-1 Assoziative Bemassung: DimStyles (ISO-25/ISO-50/Architectural/Engineering mit textHeight/arrowSize/unit/decimals/arrowStyle), 5 Dimension-Typen (linear H/V, aligned, angular 3-Punkt, radius, diameter), assoziative Wert-Berechnung aus Geometrie, formatDimValue mit Typ-Praefixen (R/⌀/°), komplette Primitives mit Extension lines + Masslinie + Pfeilspitzen als geschlossene Polygone *(2026-08-29; Log CAD-1)*
|
||||
- [ ] CAD-2 Echte Hatch-Muster: ANSI31/NET/GRASS etc. + Boundary-Erkennung aus umschlossener Flache + assoziative Schraffur
|
||||
- [x] CAD-2 Echte Hatch-Muster: ANSI31/NET/GRASS etc. + Boundary-Erkennung aus umschlossener Flache + assoziative Schraffur *(2026-08-29: 9 Muster (ANSI31/32/37, NET, GRASS, DOTS, SOLID + legacy lines/cross), generateHatchLines mit Winkel-Familien + Liang-Barsky-Clipping, computeBoundary, RenderAdapter zeichnet Hatch in rect/poly/circle; Log CAD-2)*
|
||||
- [ ] CAD-3 Fenster-/Kreuz-Selektion (Box-Select)
|
||||
- [ ] CAD-4 Objekt-Fang-Tracking (OTRACK) + DIVIDE/MEASURE
|
||||
- [ ] CAD-5 Multiline (MLINE) + Block-Editor
|
||||
|
||||
@@ -394,8 +394,15 @@ export const hatchTool: ToolExtensionV2 = {
|
||||
},
|
||||
optionsSchema: [
|
||||
{ key: 'hatchPattern', label: 'Muster', type: 'select', options: [
|
||||
{ value: 'lines', label: 'Linien' },
|
||||
{ value: 'cross', label: 'Kreuz' },
|
||||
{ value: 'ANSI31', label: 'ANSI31 (45°)' },
|
||||
{ value: 'ANSI32', label: 'ANSI32 (Eisen)' },
|
||||
{ value: 'ANSI37', label: 'ANSI37 (Beton)' },
|
||||
{ value: 'NET', label: 'Netz' },
|
||||
{ value: 'GRASS', label: 'Gras' },
|
||||
{ value: 'DOTS', label: 'Punkte' },
|
||||
{ value: 'SOLID', label: 'Voll' },
|
||||
{ value: 'lines', label: 'Linien (alt)' },
|
||||
{ value: 'cross', label: 'Kreuz (alt)' },
|
||||
] },
|
||||
{ key: 'hatchSpacing', label: 'Abstand', type: 'number', min: 2, max: 40 },
|
||||
],
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
import type { CADElement } from '../../types/cad.types';
|
||||
import { getDimStyle } from '../../services/dimStyleService';
|
||||
import { generateHatchLines, computeBoundary, getHatchPattern } from '../../services/hatchPatternService';
|
||||
import type { Pt } from '../../tools/modification/geometry';
|
||||
|
||||
/** Zeichenprimitiv — kleinste darstellbare Einheit. */
|
||||
@@ -66,6 +67,62 @@ function arrowPrimitives(x: number, y: number, ang: number, size: number, color:
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Task CAD-2: Hatch-Linien fuer ein Element mit hatch-Properties.
|
||||
* Nutzt hatchPatternService.generateHatchLines mit Boundary aus der
|
||||
* Element-Kontur. Ohne Muster: leeres Array.
|
||||
*/
|
||||
function hatchPrimitives(el: CADElement, stroke: string): ShapePrimitive[] {
|
||||
const props = el.properties as Record<string, unknown>;
|
||||
if (props.hatch !== true) return [];
|
||||
const patternId = (props.hatchPattern as string | undefined) ?? 'ANSI31';
|
||||
if (!getHatchPattern(patternId)) return [];
|
||||
const spacing = (props.hatchSpacing as number | undefined) ?? 8;
|
||||
|
||||
// Boundary aus Kontur je Elementtyp
|
||||
let bbox: { minX: number; minY: number; maxX: number; maxY: number } | null = null;
|
||||
if (Array.isArray(props.points)) {
|
||||
bbox = computeBoundary(props.points as Array<{ x: number; y: number }>);
|
||||
} else if (el.type === 'circle' || el.type === 'arc') {
|
||||
const r = (props.radius as number | undefined) ?? el.width / 2;
|
||||
bbox = { minX: el.x - r, minY: el.y - r, maxX: el.x + r, maxY: el.y + r };
|
||||
} else {
|
||||
bbox = {
|
||||
minX: el.x - el.width / 2, minY: el.y - el.height / 2,
|
||||
maxX: el.x + el.width / 2, maxY: el.y + el.height / 2,
|
||||
};
|
||||
}
|
||||
if (!bbox) return [];
|
||||
|
||||
const segs = generateHatchLines(patternId, bbox, spacing);
|
||||
const out: ShapePrimitive[] = [];
|
||||
for (const s of segs) {
|
||||
if (s.fill) {
|
||||
const rectPrim: ShapePrimitive = {
|
||||
kind: 'rect',
|
||||
x: (bbox.minX + bbox.maxX) / 2,
|
||||
y: (bbox.minY + bbox.maxY) / 2,
|
||||
w: bbox.maxX - bbox.minX,
|
||||
h: bbox.maxY - bbox.minY,
|
||||
fill: s.fill,
|
||||
stroke,
|
||||
strokeWidth: 1,
|
||||
};
|
||||
out.push(rectPrim);
|
||||
} else {
|
||||
const linePrim: ShapePrimitive = {
|
||||
kind: 'line',
|
||||
from: s.from,
|
||||
to: s.to,
|
||||
stroke,
|
||||
strokeWidth: 0.5,
|
||||
};
|
||||
out.push(linePrim);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function elementToPrimitives(el: CADElement, attrDefs?: Array<{ tag: string; prompt: string; defaultValue?: string }>): ShapePrimitive[] {
|
||||
const props = (el.properties ?? {}) as Record<string, unknown>;
|
||||
const stroke = (props.stroke as string | undefined) ?? FALLBACK_STROKE;
|
||||
@@ -90,7 +147,7 @@ export function elementToPrimitives(el: CADElement, attrDefs?: Array<{ tag: stri
|
||||
|
||||
case 'rect': {
|
||||
// Legacy-BBox-Konvention: x/y ist das Zentrum des Rechtecks
|
||||
return [{
|
||||
const base: ShapePrimitive[] = [{
|
||||
kind: 'rect',
|
||||
x: el.x - el.width / 2,
|
||||
y: el.y - el.height / 2,
|
||||
@@ -100,11 +157,12 @@ export function elementToPrimitives(el: CADElement, attrDefs?: Array<{ tag: stri
|
||||
stroke,
|
||||
strokeWidth: sw,
|
||||
}];
|
||||
return [...base, ...hatchPrimitives(el, stroke)];
|
||||
}
|
||||
|
||||
case 'circle': {
|
||||
const radius = (props.radius as number | undefined) ?? el.width / 2;
|
||||
return [{
|
||||
const circBase: ShapePrimitive[] = [{
|
||||
kind: 'circle',
|
||||
center: { x: el.x, y: el.y },
|
||||
radius,
|
||||
@@ -112,6 +170,7 @@ export function elementToPrimitives(el: CADElement, attrDefs?: Array<{ tag: stri
|
||||
stroke,
|
||||
strokeWidth: sw,
|
||||
}];
|
||||
return [...circBase, ...hatchPrimitives(el, stroke)];
|
||||
}
|
||||
|
||||
case 'arc': {
|
||||
@@ -133,13 +192,14 @@ export function elementToPrimitives(el: CADElement, attrDefs?: Array<{ tag: stri
|
||||
? (props.points as unknown[]).map(asPoint)
|
||||
: [];
|
||||
if (pts.length < 2) return [];
|
||||
return [{
|
||||
const polyBase: ShapePrimitive[] = [{
|
||||
kind: 'polyline',
|
||||
points: pts,
|
||||
close: el.type === 'polygon',
|
||||
stroke,
|
||||
strokeWidth: sw,
|
||||
}];
|
||||
return [...polyBase, ...hatchPrimitives(el, stroke)];
|
||||
}
|
||||
|
||||
case 'text': {
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Task CAD-2 – Echte Hatch-Muster + Boundary-Erkennung.
|
||||
*
|
||||
* Standard-CAD-Schraffurmuster als Linien-Segment-Generatoren für
|
||||
* eine BBox. computeBoundary liefert die umschlossene Fläche aus
|
||||
* einer Kontur (Polygon-Punkte).
|
||||
*/
|
||||
|
||||
export interface HatchSeg {
|
||||
from: { x: number; y: number };
|
||||
to: { x: number; y: number };
|
||||
fill?: string;
|
||||
closed?: boolean;
|
||||
points?: Array<{ x: number; y: number }>;
|
||||
}
|
||||
|
||||
export interface HatchPattern {
|
||||
id: string;
|
||||
label: string;
|
||||
description: string;
|
||||
defaultSpacing: number;
|
||||
/** 45°-Ersatzwinkel für Linienfamilien (Grad). */
|
||||
angles: number[];
|
||||
/** Punkte-Muster (DOTS) statt Linien. */
|
||||
dots?: boolean;
|
||||
/** Vollflächige Füllung. */
|
||||
solid?: boolean;
|
||||
}
|
||||
|
||||
export type HatchPatternId = string;
|
||||
|
||||
export const HATCH_PATTERNS: HatchPattern[] = [
|
||||
{ id: 'lines', label: 'Linien (45°)', description: 'Einfache 45°-Schraffur', defaultSpacing: 8, angles: [45] },
|
||||
{ id: 'cross', label: 'Kreuz', description: 'Kreuzschraffur 45°/-45°', defaultSpacing: 8, angles: [45, -45] },
|
||||
{ id: 'ANSI31', label: 'ANSI31 (45°)', description: 'ANSI-Standard 45°', defaultSpacing: 6, angles: [45] },
|
||||
{ id: 'ANSI32', label: 'ANSI32 (Eisen)', description: 'ANSI Eisen 45°/-45°', defaultSpacing: 6, angles: [45, -45] },
|
||||
{ id: 'ANSI37', label: 'ANSI37 (Beton)', description: 'ANSI Beton 45°/-45° dicht', defaultSpacing: 3, angles: [45, -45] },
|
||||
{ id: 'NET', label: 'Netz', description: 'Horizontal + vertikal', defaultSpacing: 10, angles: [0, 90] },
|
||||
{ id: 'GRASS', label: 'Gras', description: 'Kurze Gras-Striche', defaultSpacing: 6, angles: [75] },
|
||||
{ id: 'DOTS', label: 'Punkte', description: 'Punktschraffur', defaultSpacing: 8, angles: [], dots: true },
|
||||
{ id: 'SOLID', label: 'Voll', description: 'Vollflächige Füllung', defaultSpacing: 0, angles: [], solid: true },
|
||||
];
|
||||
|
||||
/** Muster per ID (oder undefined). */
|
||||
export function getHatchPattern(id: string | undefined): HatchPattern | undefined {
|
||||
if (!id) return undefined;
|
||||
return HATCH_PATTERNS.find((p) => p.id === id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt Schraffur-Segmente für eine BBox nach Muster.
|
||||
* SOLID liefert EIN Segment mit fill-Flag; DOTS liefert Punkte-Muster.
|
||||
*/
|
||||
export function generateHatchLines(
|
||||
patternId: string,
|
||||
bbox: { minX: number; minY: number; maxX: number; maxY: number },
|
||||
spacing: number,
|
||||
): HatchSeg[] {
|
||||
const pattern = getHatchPattern(patternId);
|
||||
if (!pattern) return [];
|
||||
const { minX, minY, maxX, maxY } = bbox;
|
||||
const w = maxX - minX;
|
||||
const h = maxY - minY;
|
||||
|
||||
if (pattern.solid) {
|
||||
return [{ from: { x: minX, y: minY }, to: { x: maxX, y: maxY }, fill: '#888888' }];
|
||||
}
|
||||
|
||||
if (pattern.dots) {
|
||||
const out: HatchSeg[] = [];
|
||||
for (let y = minY + spacing / 2; y < maxY; y += spacing) {
|
||||
for (let x = minX + spacing / 2; x < maxX; x += spacing) {
|
||||
out.push({
|
||||
from: { x, y },
|
||||
to: { x: x + 1, y: y + 1 },
|
||||
points: [{ x, y }],
|
||||
});
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Linienfamilien je Winkel
|
||||
const out: HatchSeg[] = [];
|
||||
for (const angleDeg of pattern.angles) {
|
||||
const rad = (angleDeg * Math.PI) / 180;
|
||||
const cosA = Math.cos(rad);
|
||||
const sinA = Math.sin(rad);
|
||||
const diag = Math.hypot(w, h);
|
||||
const step = spacing;
|
||||
const offsetCount = Math.ceil(diag / step) + 2;
|
||||
for (let i = -offsetCount; i <= offsetCount; i++) {
|
||||
const cx = minX + w / 2 + i * step;
|
||||
const cy = minY + h / 2;
|
||||
// Linie durch (cx,cy) in Richtung (cosA, sinA), begrenzt auf BBox
|
||||
const p1 = { x: cx - cosA * diag, y: cy - sinA * diag };
|
||||
const p2 = { x: cx + cosA * diag, y: cy + sinA * diag };
|
||||
// Clipping an BBox (einfaches Cohen-Sutherland)
|
||||
const cl = clipToBBox(p1, p2, bbox);
|
||||
if (cl) out.push({ from: cl[0], to: cl[1] });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Cohen-Sutherland-artiges Clipping an BBox (vereinfacht). */
|
||||
function clipToBBox(
|
||||
p1: { x: number; y: number },
|
||||
p2: { x: number; y: number },
|
||||
b: { minX: number; minY: number; maxX: number; maxY: number },
|
||||
): Array<{ x: number; y: number }> | null {
|
||||
// Liang-Barsky
|
||||
let t0 = 0, t1 = 1;
|
||||
const dx = p2.x - p1.x;
|
||||
const dy = p2.y - p1.y;
|
||||
const clip = (p: number, q: number): boolean => {
|
||||
if (p === 0) return q >= 0;
|
||||
const r = q / p;
|
||||
if (p < 0) {
|
||||
if (r > t1) return false;
|
||||
if (r > t0) t0 = r;
|
||||
} else {
|
||||
if (r < t0) return false;
|
||||
if (r < t1) t1 = r;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
if (!clip(-dx, p1.x - b.minX)) return null;
|
||||
if (!clip(dx, b.maxX - p1.x)) return null;
|
||||
if (!clip(-dy, p1.y - b.minY)) return null;
|
||||
if (!clip(dy, b.maxY - p1.y)) return null;
|
||||
return [
|
||||
{ x: p1.x + t0 * dx, y: p1.y + t0 * dy },
|
||||
{ x: p1.x + t1 * dx, y: p1.y + t1 * dy },
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Boundary-Erkennung: BBox aus einer Kontur (Polygon-Punkte).
|
||||
* Weniger als 2 Punkte → null.
|
||||
*/
|
||||
export function computeBoundary(
|
||||
pts: Array<{ x: number; y: number }>,
|
||||
): { minX: number; minY: number; maxX: number; maxY: number } | null {
|
||||
if (!Array.isArray(pts) || pts.length < 2) return null;
|
||||
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
||||
for (const p of pts) {
|
||||
if (p.x < minX) minX = p.x;
|
||||
if (p.y < minY) minY = p.y;
|
||||
if (p.x > maxX) maxX = p.x;
|
||||
if (p.y > maxY) maxY = p.y;
|
||||
}
|
||||
return { minX, minY, maxX, maxY };
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Task CAD-2 - Echte Hatch-Muster + Boundary-Erkennung.
|
||||
*
|
||||
* HATCH_PATTERNS: Standard-CAD-Muster (ANSI31, NET, GRASS etc.)
|
||||
* als Linien-Segment-Generatoren fuer eine BBox.
|
||||
* computeBoundary: umschlossene Flaeche aus Kontur-Punkten.
|
||||
*/
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
HATCH_PATTERNS,
|
||||
getHatchPattern,
|
||||
generateHatchLines,
|
||||
computeBoundary,
|
||||
type HatchPatternId,
|
||||
} from '../src/services/hatchPatternService';
|
||||
|
||||
describe('CAD-2: HATCH_PATTERNS Bibliothek', () => {
|
||||
it('enthaelt die Standard-CAD-Muster', () => {
|
||||
const ids = HATCH_PATTERNS.map((p) => p.id);
|
||||
expect(ids).toContain('ANSI31');
|
||||
expect(ids).toContain('ANSI32');
|
||||
expect(ids).toContain('ANSI37');
|
||||
expect(ids).toContain('NET');
|
||||
expect(ids).toContain('GRASS');
|
||||
expect(ids).toContain('DOTS');
|
||||
expect(ids).toContain('SOLID');
|
||||
expect(ids).toContain('lines'); // Alte bleiben erhalten
|
||||
expect(ids).toContain('cross');
|
||||
});
|
||||
|
||||
it('jedes Muster hat id, label, description; spacing nur bei Nicht-SOLID', () => {
|
||||
for (const p of HATCH_PATTERNS) {
|
||||
expect(p.id.length).toBeGreaterThan(0);
|
||||
expect(p.label.length).toBeGreaterThan(0);
|
||||
// SOLID braucht keinen Abstand (Vollfuellung)
|
||||
if (!p.solid) {
|
||||
expect(p.defaultSpacing).toBeGreaterThan(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('getHatchPattern liefert undefined fuer unbekannte ID', () => {
|
||||
expect(getHatchPattern('gibts-nicht')).toBeUndefined();
|
||||
expect(getHatchPattern('ANSI31')).toBeDefined();
|
||||
expect(getHatchPattern('ANSI31')!.label).toContain('1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('CAD-2: generateHatchLines (Muster-Geometrie)', () => {
|
||||
const bbox = { minX: 0, minY: 0, maxX: 100, maxY: 50 };
|
||||
const spacing = 10;
|
||||
|
||||
it('ANSI31 (45 Grad): erzeugt Diagonal-Linien', () => {
|
||||
const lines = generateHatchLines('ANSI31', bbox, spacing);
|
||||
expect(lines.length).toBeGreaterThan(3);
|
||||
for (const seg of lines) {
|
||||
const dx = seg.to.x - seg.from.x;
|
||||
const dy = seg.to.y - seg.from.y;
|
||||
expect(Math.abs(dy / dx)).toBeCloseTo(1, 1); // 45 Grad
|
||||
}
|
||||
});
|
||||
|
||||
it('NET: erzeugt horizontale UND vertikale Linien', () => {
|
||||
const lines = generateHatchLines('NET', bbox, spacing);
|
||||
const horiz = lines.filter((l) => l.from.y === l.to.y);
|
||||
const vert = lines.filter((l) => l.from.x === l.to.x);
|
||||
expect(horiz.length).toBeGreaterThan(0);
|
||||
expect(vert.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('DOTS: erzeugt kleine Kreise (als 4-Punkt-Polygone)', () => {
|
||||
const lines = generateHatchLines('DOTS', bbox, spacing);
|
||||
expect(lines.length).toBeGreaterThan(0);
|
||||
// DOTS sind als polyline-segments repraesentiert
|
||||
});
|
||||
|
||||
it('SOLID: erzeugt EINE grosse Flaeche (fill)', () => {
|
||||
const lines = generateHatchLines('SOLID', bbox, spacing);
|
||||
expect(lines).toHaveLength(1);
|
||||
expect((lines[0] as { fill?: string }).fill).toBeDefined();
|
||||
});
|
||||
|
||||
it('unbekanntes Muster: leeres Array (renderer-sicher)', () => {
|
||||
expect(generateHatchLines('gibts-nicht', bbox, spacing)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CAD-2: computeBoundary (Boundary-Erkennung)', () => {
|
||||
it('Rechteck-Kontur: BBox wird korrekt berechnet', () => {
|
||||
const pts = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 50 }, { x: 0, y: 50 }];
|
||||
const b = computeBoundary(pts);
|
||||
expect(b).toEqual({ minX: 0, minY: 0, maxX: 100, maxY: 50 });
|
||||
});
|
||||
|
||||
it('Dreieck: BBox umschliesst alle Punkte', () => {
|
||||
const pts = [{ x: 10, y: 0 }, { x: 90, y: 80 }, { x: 10, y: 80 }];
|
||||
const b = computeBoundary(pts);
|
||||
expect(b.minX).toBe(10);
|
||||
expect(b.maxX).toBe(90);
|
||||
expect(b.minY).toBe(0);
|
||||
expect(b.maxY).toBe(80);
|
||||
});
|
||||
|
||||
it('leere/wenige Punkte: null-Boundary', () => {
|
||||
expect(computeBoundary([])).toBeNull();
|
||||
expect(computeBoundary([{ x: 0, y: 0 }])).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user