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 canExtrudeSelectionItem and getSelectionType for multiple selections #3884

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/lib/selections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,14 @@ export function canFilletSelection(selection: Selections) {
}

function canExtrudeSelectionItem(selection: Selections, i: number) {
const isolatedSelection = {
...selection,
codeBasedSelections: [selection.codeBasedSelections[i]],
}
const commonNode = buildCommonNodeFromSelection(selection, i)

return (
!!isSketchPipe(selection) &&
!!isSketchPipe(isolatedSelection) &&
nodeHasClose(commonNode) &&
!nodeHasExtrude(commonNode)
)
Expand All @@ -455,25 +459,17 @@ export type ResolvedSelectionType = [Selection['type'] | 'other', number]
export function getSelectionType(
selection: Selections
): ResolvedSelectionType[] {
return selection.codeBasedSelections
.map((s, i) => {
if (canExtrudeSelectionItem(selection, i)) {
return ['extrude-wall', 1] as ResolvedSelectionType // This is implicitly determining what a face is, which is bad
} else {
return ['other', 1] as ResolvedSelectionType
}
})
.reduce((acc, [type, count]) => {
const foundIndex = acc.findIndex((item) => item && item[0] === type)

if (foundIndex === -1) {
return [...acc, [type, count]]
} else {
const temp = [...acc]
temp[foundIndex][1] += count
return temp
}
}, [] as ResolvedSelectionType[])
const extrudableCount = selection.codeBasedSelections.filter((_, i) => {
const singleSelection = {
...selection,
codeBasedSelections: [selection.codeBasedSelections[i]],
}
Comment on lines +463 to +466
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is likely a nit, but aren't you already set up to isolate the codeBasedSelections up within the canExtrudeSelectionItem function itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nah, can extrude selection gets as an argument the whooooole list of selections and an index of the one to check. While isSketchPile is expecting only one argument - selection. Not selection+index. So it gets the whole array of selections and just fails to work with it.
Screenshot 2024-09-17 at 22 19 10

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we should rethink the generic approach in future.
@franknoirot
agree, those are good points, probably will be covered by #3837

return canExtrudeSelectionItem(singleSelection, 0)
}).length

return extrudableCount === selection.codeBasedSelections.length
? [['extrude-wall', extrudableCount]]
: [['other', selection.codeBasedSelections.length]]
}

export function getSelectionTypeDisplayText(
Expand Down
Loading