Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(removeAllSegmentations): iteration bug in removeAllSegmentations that prevents proper removal #1734

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stada526
Copy link
Contributor

@stada526 stada526 commented Dec 30, 2024

Context

The removeAllSegmentations function doesn't remove all segmentations properly due to a reference problem in iteration.
The simple examples below demonstrate why the current implementation doesn't work.

Incorrect

const list = [0, 1, 2]

list.forEach((x, index) => {
    console.log("----")
    console.log(list)
    console.log(x)
    if (index === 0) {
        list.shift()
    }
})

// "----" 
// [0, 1, 2] 
// 0 
// "----" 
// [1, 2] 
// 2 

Correct

const list = [0, 1, 2]

list.map(x => x).forEach((x, index) => {
    console.log("----")
    console.log(list)
    console.log(x)
    if (index === 0) {
        list.shift()
    }
})

// "----" 
// [0, 1, 2] 
// 0 
// "----" 
// [1, 2] 
// 1 
// "----" 
// [1, 2] 
// 2 

Changes & Results

  • Create segmentationIds, an array containing segmentation IDs
  • Iterate over segmentationIds to call removeSegmentation for each ID.

Testing

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • "OS: maxOS 15.1
  • "Node version: v21.7.1
  • "Browser: Chrome 130.0.6723.117

Copy link

stackblitz bot commented Dec 30, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

netlify bot commented Dec 30, 2024

Deploy Preview for cornerstone-3d-docs failed. Why did it fail? →

Name Link
🔨 Latest commit 0a852a9
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-3d-docs/deploys/677260b04a58160008eda4ac

@stada526 stada526 changed the title Fix(removeAllSegmentations): a bug to ensure all segmentations are removed Fix(removeAllSegmentations): iteration bug in removeAllSegmentations that prevents proper removal Dec 30, 2024
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.

1 participant