Bug 161555 - Missing shape algebra operation: Fragment
Summary: Missing shape algebra operation: Fragment
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Shapes
  Show dependency treegraph
 
Reported: 2024-06-13 21:33 UTC by Eyal Rozenberg
Modified: 2024-06-14 19:24 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eyal Rozenberg 2024-06-13 21:33:28 UTC
A vectorized drawing editor with geometric shapes support needs operations involving the algebra of regions induced by shapes.

LibreOffice has:

Merge (i.e. Union)
Subtract
Intersect

as well as an odd Combine operation, whose logic is: "Define a new shape whose counter is the bounding rectangle of the union of the selected shapes; and for every region in the algebra induced by the selected shapes, make it opaque in the color of the first selected shape if the number of shapes containing this region is odd, or transparent if the number of containing shapes is even." 

... weird, but I guess that might come in handy.

However, LO is lacking the operation which can be used to achieve the effect of any of the other four! This is the "Fragment" operation, which exposes the full induced algebra: Defining a separate object for every one of the regions induced by the selected shapes. So, if my shapes are:

  +------+
  |      |
  |      |
  |   +--+----+
  |   |  |    |
  +---+--+    +
      |       |
      +-------+

The result of the operation would be three shapes: The top-left angle, the bottom-right angle, and the middle rectangle - each with a nice contour - and lets say, the fill of the topmost shape covering them (so if there is no transparency, you only get some added counters).

Naturally, with this atomic sets of the algebra you can construct any set you like (at least if we ignore contours) in the algebra, including the union, intersection, difference, the XOR-ish Combine operation etc.
   
So please add it.
Comment 1 Regina Henschel 2024-06-13 22:08:47 UTC
Mark the two objects together and create two copies of the pair. With first pair do "Subtract", with second pair do "Intersect". In third pair put front object back and do "Subtract".

I do not think, that such "Fragment" operation is so often requested, that a special command is necessary.
Comment 2 Eyal Rozenberg 2024-06-13 22:26:51 UTC
(In reply to Regina Henschel from comment #1)
> I do not think, that such "Fragment" operation is so often requested, that a
> special command is necessary.

As opposed to XOR-combine? Come on....

> Mark the two objects together and create two copies of the pair. With first
> pair do "Subtract", with second pair do "Intersect". In third pair put front
> object back and do "Subtract".

This won't even work as described, because the overlapping copies will prevent me from making the right selections. But if I do move the shape copies out of the way, I will then need to move the operated-on shapes back, and make sure they line up perfectly - which also means having to write down the exact coordinates. And that might not even be possible, since the shape properties limits the accuracy of coordinate entry. And I haven't even mentioned the need to make sure that where I move the copy, it's all clear so that I don't drag other shapes back by mistake...

So, that's not even effectively a solution - and if it were, it would require a inordinate amount of effort.


Also, let's also look at MS Visio's shape operations:

https://youtu.be/jPocgphVUyE?si=-eVvBj9dFkxLip-K&t=76

Union, Combine, Fragment, Intersect, Subtract

guess which one we're missing? :-(
Comment 3 Regina Henschel 2024-06-13 23:38:12 UTC
(In reply to Eyal Rozenberg from comment #2)
> (In reply to Regina Henschel from comment #1)
> > Mark the two objects together and create two copies of the pair. With first
> > pair do "Subtract", with second pair do "Intersect". In third pair put front
> > object back and do "Subtract".
> 
> This won't even work as described, because the overlapping copies will
> prevent me from making the right selections.

Of cause you need to move them away. After Ctrl+V the pair is still marked and can be quickly moved away.

 But if I do move the shape
> copies out of the way, I will then need to move the operated-on shapes back,
> and make sure they line up perfectly - which also means having to write down
> the exact coordinates.

You can enable the option "snap to object point" and drag them together.

 And that might not even be possible, since the shape
> properties limits the accuracy of coordinate entry. And I haven't even
> mentioned the need to make sure that where I move the copy, it's all clear
> so that I don't drag other shapes back by mistake...

You know that you can edit objects outside the page?

> 
> So, that's not even effectively a solution - and if it were, it would
> require a inordinate amount of effort.
> 
> 
> Also, let's also look at MS Visio's shape operations:
> 
> https://youtu.be/jPocgphVUyE?si=-eVvBj9dFkxLip-K&t=76
> 
> Union, Combine, Fragment, Intersect, Subtract
> 
> guess which one we're missing? :-(

How often do you need it? The effort is 1 minute.

If others agree with you that it is a desirable feature, it is an enhancement request not a bug.
Comment 4 Heiko Tietze 2024-06-14 06:07:30 UTC
You could also put the couple of commands into a macro.

(In reply to Regina Henschel from comment #1)
> I do not think, that such "Fragment" operation is so often requested, that a
> special command is necessary.
+1
Comment 5 Eyal Rozenberg 2024-06-14 11:02:52 UTC
I was about to argue the details, but this whole method doesn't even work.

Suppose you take a square, copy it, rotate the copy by 45 degrees, and take the fragmentation. The number of regions is now 9, not 3. How would you address this?

(In reply to Regina Henschel from comment #3)
> The effort is 1 minute.

Let's grant that for the moment (even though it can't even be done at all in the general case, it seems). So, 1 minute for 3 regions, or 20 seconds per region. Let's even say it's much lower - just 5 seconds per region, since I'm kind of quick and experienced. Or 15 seconds in total. Easy peasy.

Now I have, say, 10 shapes selected. How many regions are there in the fragmentation? You saw my example above. It's not even as low as 2^10! It's probably something like the product of all numbers of edges of the shapes, perhaps minus 1? So, 10 rectangles - maybe... 3^10 or so. How much time would that take me to do manually?

(In reply to Heiko Tietze from comment #4)
> You could also put the couple of commands into a macro.

Really? Please sketch out the code for that macro. For the general case of N shapes of course.
Comment 6 Regina Henschel 2024-06-14 15:17:32 UTC
I admit that a solution for more than two shapes with the UI is too complex. A solution using macros is also complex because the required methods from basegfx are not available in macros but only the .uno commands can be used if you do not want to emulate the methods from basegfx as macro methods. Problems with the intersect and subtract .uno commands are: the shapes need to be inserted in a page, they relay on z-order, they work with a marked objects collection 
on the view.

So I now think, it is a valid feature request. 

(In reply to Eyal Rozenberg from comment #5)
> Really? Please sketch out the code for that macro. For the general case of N
> shapes of course.

An algorithm looks straight forward to me in principle, but details are complex:

Copy first shape from collection into result vector.
for each shape in collection starting with second shape
do
  prepare temp vector
  current shape = next shape from collection.
  for each shape of result vector
  do 
    subtract current shape from result vector shape and add this subtraction to temp vector.
  for each shape of result vector
  do
    subtract result vector shape from current shape and add this subtraction to temp vector.
  for each shape of result vector
  do
    intersect current shape with result vector shape and add this intersection to temp vector.
  replace result vector with temp vector.
next
return result vector
Comment 7 Eyal Rozenberg 2024-06-14 18:46:21 UTC
(In reply to Regina Henschel from comment #6)
> An algorithm looks straight forward to me in principle, but details are
> complex:

Yes, that's what I meant to get Heiko to say... we can't expect users, even advanced users, to do tricky macro programming to that degree.
Comment 8 Telesto 2024-06-14 19:06:56 UTC
It seems a valid request to me. Same at comment 6. Let's mark it NEW
Comment 9 Eyal Rozenberg 2024-06-14 19:24:30 UTC
(In reply to Telesto from comment #8)
> It seems a valid request to me. Same at comment 6. Let's mark it NEW

I disagree that this is merely an enhancement, because given that we have shape-algebraic ops, this one is necessary. But - I'll let it go...