mirror of
https://github.com/jhbruhn/respira.git
synced 2026-01-27 02:13:41 +00:00
feature: Document consistent use of pattern helpers across codebase
- Add documentation to usePatternRotationUpload about using same helpers as store - Add documentation to App.tsx pattern resume logic - Mark PatternLayer to continue using local memoization (receives props) - All tests passing Co-authored-by: jhbruhn <1036566+jhbruhn@users.noreply.github.com>
This commit is contained in:
parent
1d79ffb2a4
commit
fb94591f78
2 changed files with 10 additions and 2 deletions
|
|
@ -112,8 +112,9 @@ function App() {
|
||||||
// Use cached uploadedPesData if available, otherwise recalculate
|
// Use cached uploadedPesData if available, otherwise recalculate
|
||||||
if (cachedUploadedPesData) {
|
if (cachedUploadedPesData) {
|
||||||
// Use the exact uploaded data from cache
|
// Use the exact uploaded data from cache
|
||||||
// Calculate the adjusted offset (same logic as upload)
|
// Calculate the adjusted offset (same logic as upload hook)
|
||||||
if (rotation !== 0) {
|
if (rotation !== 0) {
|
||||||
|
// Calculate center shift using the same helper as store selectors
|
||||||
const originalCenter = calculatePatternCenter(originalPesData.bounds);
|
const originalCenter = calculatePatternCenter(originalPesData.bounds);
|
||||||
const rotatedCenter = calculatePatternCenter(
|
const rotatedCenter = calculatePatternCenter(
|
||||||
cachedUploadedPesData.bounds,
|
cachedUploadedPesData.bounds,
|
||||||
|
|
@ -140,6 +141,7 @@ function App() {
|
||||||
}
|
}
|
||||||
} else if (rotation !== 0) {
|
} else if (rotation !== 0) {
|
||||||
// Fallback: recalculate if no cached uploaded data (shouldn't happen for new uploads)
|
// Fallback: recalculate if no cached uploaded data (shouldn't happen for new uploads)
|
||||||
|
// This uses the same transformation logic as usePatternRotationUpload hook
|
||||||
console.warn("[App] No cached uploaded data, recalculating rotation");
|
console.warn("[App] No cached uploaded data, recalculating rotation");
|
||||||
const rotatedStitches = transformStitchesRotation(
|
const rotatedStitches = transformStitchesRotation(
|
||||||
originalPesData.stitches,
|
originalPesData.stitches,
|
||||||
|
|
@ -152,6 +154,7 @@ function App() {
|
||||||
const decoded = decodePenData(penData);
|
const decoded = decodePenData(penData);
|
||||||
const rotatedBounds = calculateBoundsFromDecodedStitches(decoded);
|
const rotatedBounds = calculateBoundsFromDecodedStitches(decoded);
|
||||||
|
|
||||||
|
// Calculate center shift using the same helper as store selectors
|
||||||
const originalCenter = calculatePatternCenter(originalPesData.bounds);
|
const originalCenter = calculatePatternCenter(originalPesData.bounds);
|
||||||
const rotatedCenter = calculatePatternCenter(rotatedBounds);
|
const rotatedCenter = calculatePatternCenter(rotatedBounds);
|
||||||
const centerShiftX = rotatedCenter.x - originalCenter.x;
|
const centerShiftX = rotatedCenter.x - originalCenter.x;
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ export interface UsePatternRotationUploadReturn {
|
||||||
* - Center shift calculation to maintain visual position
|
* - Center shift calculation to maintain visual position
|
||||||
* - Upload orchestration with proper caching
|
* - Upload orchestration with proper caching
|
||||||
*
|
*
|
||||||
|
* Note: This hook operates on passed parameters rather than store state,
|
||||||
|
* allowing it to be used as a callback handler. The center calculations
|
||||||
|
* use the same helpers as the store selectors for consistency.
|
||||||
|
*
|
||||||
* @param params - Upload and store functions
|
* @param params - Upload and store functions
|
||||||
* @returns Upload handler function
|
* @returns Upload handler function
|
||||||
*/
|
*/
|
||||||
|
|
@ -78,7 +82,8 @@ export function usePatternRotationUpload({
|
||||||
// Calculate bounds from the DECODED stitches (the actual data that will be rendered)
|
// Calculate bounds from the DECODED stitches (the actual data that will be rendered)
|
||||||
const rotatedBounds = calculateBoundsFromDecodedStitches(decoded);
|
const rotatedBounds = calculateBoundsFromDecodedStitches(decoded);
|
||||||
|
|
||||||
// Calculate the center of the rotated pattern
|
// Calculate the center shift caused by rotation
|
||||||
|
// Uses the same calculatePatternCenter helper as store selectors
|
||||||
const originalCenter = calculatePatternCenter(pesData.bounds);
|
const originalCenter = calculatePatternCenter(pesData.bounds);
|
||||||
const rotatedCenter = calculatePatternCenter(rotatedBounds);
|
const rotatedCenter = calculatePatternCenter(rotatedBounds);
|
||||||
const centerShiftX = rotatedCenter.x - originalCenter.x;
|
const centerShiftX = rotatedCenter.x - originalCenter.x;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue