Skip to content

Commit

Permalink
Fix canExtrudeSelectionItem and getSelectionType for multiple selecti…
Browse files Browse the repository at this point in the history
…ons (#3884)

* fix isSketchPipe in canExtrudeSelectionItem

* fix count in getSelectionType

used to count only same type as first selection
  • Loading branch information
max-mrgrsk authored Sep 17, 2024
1 parent f828c36 commit 62b7884
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/lib/selections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,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 @@ -460,25 +464,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]],
}
return canExtrudeSelectionItem(singleSelection, 0)
}).length

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

export function getSelectionTypeDisplayText(
Expand Down

0 comments on commit 62b7884

Please sign in to comment.