Skip to content

Conversation

@andeplane
Copy link
Owner

@andeplane andeplane commented Nov 1, 2025

Summary

Fixes #186

Refactors all three sync modifiers to use the shared processData1D() helper function, reducing each file from ~125 lines to ~50-60 lines.

Changes

Refactored:

  • src/modifiers/synccomputesmodifier.ts
  • src/modifiers/syncfixesmodifier.ts
  • src/modifiers/syncvariablesmodifier.ts

Each modifier now:

  • Calls the appropriate sync method (syncComputes, syncFixes, or syncVariables)
  • Gets the appropriate name array (getComputeNames, getFixNames, or getVariableNames)
  • Loops through names to create/update modifier objects
  • Calls the shared processData1D() function for Data1D processing
  • Assigns to the appropriate output collection

Benefits

  • Significant reduction in code duplication: Each file reduced by ~50%
  • Easier to maintain and test: Changes to Data1D processing logic happen in one place
  • Consistent behavior: All sync modifiers use the same processing logic
  • Makes it easier to add new modifiers: Clear pattern to follow

Prerequisites

Requires #185 to be completed first (extraction of shared Data1D processing logic).


This pull request contains changes generated by a Cursor Cloud Agent

Open in Cursor Open in Web

- Extract common Data1D processing logic into processData1D() helper function
- Refactor synccomputesmodifier.ts, syncfixesmodifier.ts, and syncvariablesmodifier.ts to use shared function
- Reduce code duplication from ~125 lines to ~70-73 lines per file
- Maintain all unique logic (execute checks, sync calls, name array handling)

Closes #186
@cursor
Copy link

cursor bot commented Nov 1, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@andeplane andeplane changed the title Solve issue 186 and create PR refactor: Refactor sync modifiers to use shared Data1D processing logic Nov 1, 2025
@andeplane
Copy link
Owner Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great refactoring that significantly reduces code duplication by extracting shared logic into a processData1D helper function. This improves maintainability and consistency across the sync modifiers. My review includes a few minor suggestions for the new helper function to enhance performance and readability.

- Optimize size() call: store data1DNamesSize once instead of calling twice
- Remove redundant check: currentData1D is guaranteed to be an object
- Replace magic number 4 with Float32Array.BYTES_PER_ELEMENT for clarity
@andeplane
Copy link
Owner Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent refactoring that significantly reduces code duplication by introducing the processData1D helper function. This greatly improves maintainability and consistency across the sync modifiers. The changes are clear and follow the stated goals in the pull request description. I have one minor suggestion to improve the readability of the data processing loop in the new helper function.

Comment on lines 75 to 80
for (let k = lengthBeforeWeStart; k < xValues.length; k++) {
if (j === 0) {
currentData1D.data.push([xValues[k]]);
}
currentData1D.data[k].push(yValues[k]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current logic for populating currentData1D.data is functionally correct, but it could be made more explicit to improve readability. By using an if/else block, you can clearly separate the logic for initializing a new row (for j === 0) from appending to an existing row (for j > 0). This makes the intent of the code easier to grasp at a glance.

Suggested change
for (let k = lengthBeforeWeStart; k < xValues.length; k++) {
if (j === 0) {
currentData1D.data.push([xValues[k]]);
}
currentData1D.data[k].push(yValues[k]);
}
for (let k = lengthBeforeWeStart; k < xValues.length; k++) {
if (j === 0) {
currentData1D.data.push([xValues[k], yValues[k]]);
} else {
currentData1D.data[k].push(yValues[k]);
}
}

cursoragent and others added 2 commits November 1, 2025 11:53
Use if/else block to clearly separate logic for initializing new row (j === 0) from appending to existing row (j > 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Refactor sync modifiers to use shared Data1D processing logic

3 participants