// scoring.js — accuracy calculation const Scoring = (() => { /** * Calculate a score from the drawn path points. * NOTE: Currently uses an effort-based approximation. * TODO: Replace with real polygon comparison (IoU or Hausdorff distance). * @param {{ x: number, y: number }[]} drawnPoints * @returns {number} Score between 0 and 100. */ function calculateScore(drawnPoints) { if (!drawnPoints || drawnPoints.length < 10) return 0; const effort = Math.min(drawnPoints.length / 300, 1); // 0–1 const base = 40 + Math.round(effort * 45); // 40–85 const jitter = Math.round((Math.random() - 0.5) * 14); // ±7 return Math.max(0, Math.min(100, base + jitter)); } /** * Compare a drawn polygon against a reference polygon. * Stub — reserved for future IoU / Hausdorff implementation. * @param {{ x: number, y: number }[]} _drawnPoints * @param {{ x: number, y: number }[]} _referencePolygon - Normalised 0–1 coords. * @returns {number} Score between 0 and 100. */ function compareShapes(_drawnPoints, _referencePolygon) { // TODO: implement real shape comparison return 0; } /** * Map a numeric score to a letter grade with colour. * @param {number} score * @returns {{ label: string, color: string }} */ function getGrade(score) { if (score >= 90) return { label: "S", color: "#f0b429" }; if (score >= 75) return { label: "A", color: "#41b869" }; if (score >= 60) return { label: "B", color: "#1a7fc4" }; if (score >= 40) return { label: "C", color: "#7a9aaa" }; return { label: "D", color: "#e05c5c" }; } return { calculateScore, compareShapes, getGrade }; })();