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

Add a stack-based Boolean Operation layer node #1813

Merged
merged 10 commits into from
Jul 10, 2024
Merged

Conversation

adamgerhant
Copy link
Collaborator

@adamgerhant adamgerhant commented Jul 7, 2024

Closes #1816

Adds a layer Boolean operation node which performs the Boolean operation on an entire stack of vector data. This means the layer panel can now be used to adjust the operation order.

chrome_D7jptsQ7ZW.mp4

Since operations can now be performed on more than 2 shapes, the order and merging of these operations into a single vector will have to be carefully considered.

  • Union: Accumulate all shapes into a single result by repeatedly setting the result to the union of of each layer and the result.
  • Subtract front: Union all shapes other than the first shape, then subtract the first shape from this union.
  • Subtract back: Rotate the list of vector data right one so that the last shape is at the start of the list, and subtract front.
  • Intersect (area where all shapes overlap): Accumulate all shapes into a single result by repeatedly setting the result to the intersection of each layer and the result.
  • Difference (area where no shapes overlap): Accumulate all shapes into a single result by repeatedly finding intersection of each layer and the result, then union this intersection with the result. This provides the area where there is at least one intersection. Then find the union of all shapes, and subtract the result.
  • Divide (Show all lines for each shape): Not currently implemented due to limitations with current rendering method.

Another consideration is that a GraphicGroup can contain elements other than vector data. Currently, each element can be either another GraphicGroup, VectorData, Image, or Artboard. For GraphicGroup's and Artboards, a recursive Boolean union is applied to convert them into a a single vector. Image's are treated as default rectangles based on their height, width, and position, although this will have to be reworked. Maybe a mask should be used instead of the Boolean operation?

It would also be helpful to allow the user to specify a minimum and maximum number of overlaps for the resulting shape. For example a union would have a minimum of 0 overlaps and no maximum, intersect sets the minimum to the number of shapes - 1 and no maximum, and difference sets the minimum to 0 and maximum to 1. The UI for this could be a single slider bar with the number of ticks equal to the number of shapes in the stack, and 2 selectors for the minimum and maximum. This could be a new node "Intersect".

A more flexible implementation for the Boolean operation could take the following inputs: List of vector data (GraphicGroup), minimum overlap(RelativeOffset), maximum overlap (RelativeOffset), subtract index (Option<RelativeOffset>). The relative offset will be an enum with 2 varients, FromStart(usize) and FromBack(usize). This is necessary to ensure indices can be based of either the start of end of the vector data, so that adding a new item to the stack does not require the indices to be manually updated. For example, union will store a minimum offset of RelativeOffset::FromStart(0) and a maximum offset of RelativeOffset::FromEnd(0).

Since subtracting is fundamentally different than the intersection selection, it should be a separate node. If the subtract index is Some, then it will get that index from the list of vector data and subtract it from the Union of all vector data. This Union will be created by output of the new Intersect node.

Implementation sketch:
new boolean operation

@Keavon Keavon changed the title Boolean operation layer node Add a stack-based input variant of the Boolean Operation layer node Jul 8, 2024
@Keavon Keavon changed the title Add a stack-based input variant of the Boolean Operation layer node Add a stack-based Boolean Operation layer node Jul 8, 2024
@adamgerhant adamgerhant force-pushed the layer-boolean-operation branch from c003bd9 to 92c81a0 Compare July 9, 2024 05:45
@Keavon Keavon force-pushed the layer-boolean-operation branch from 92c81a0 to 750a75c Compare July 9, 2024 11:32
@Keavon Keavon merged commit 9d749c4 into master Jul 10, 2024
2 checks passed
@Keavon Keavon deleted the layer-boolean-operation branch July 10, 2024 09:12
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.

Multi-input boolean operations supporting groups
2 participants