JuliaPolyhedra / Polyhedra.jl

Polyhedral Computation Interface
Other
172 stars 27 forks source link

In-place translation and rotation / preserving the representations #246

Open anicusan opened 3 years ago

anicusan commented 3 years ago

In its current implementation, the translate function creates a new object for the translated polyhedron. In cases where a large number of translations are applied, this quickly becomes an unnecessary copy.

Can we implement an in-place version translate!(p::Polyhedron, v) that does not create a new object when the translation is applied? As an extension to my previous issue #245 , can we implement an in-place version of the hypothetical rotate function too?

One final point that is closely related to the translate function - this code from the source:

function translate(p::Polyhedron, v)
    if hrepiscomputed(p)
        htranslate(p, v)
    else
        vtranslate(p, v)
    end
end

When a translation is applied to a Polyhedron that has both the H- and the V-representations computed, the V-representation is lost, incurring an expensive recomputation step needed every time translate is used. Can we preserve both representations? Thinking of the implementation, this would need to use the in-place version of translate for each representation, respectively.

blegat commented 3 years ago

That should be possible indeed. There is in fact even a quite elegant way to do this now with https://github.com/jump-dev/MutableArithmetics.jl. I'l try to do it today.