pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.14k stars 108 forks source link

exact bounding box for cubic bezier paths #633

Open pgf-tikz-bot opened 6 years ago

pgf-tikz-bot commented 6 years ago

Migrated from SourceForge Author: linusromer Timestamp: 2017-12-19 17:33:59.946000

tikzpicture should have a boolean option exactboundingbox (or something similar) that calculates the bounding box of pictures containing cubic bezier paths exactely (up to numeric precision): https://tex.stackexchange.com/questions/406777/tikz-bounding-box-of-a-cubic-b%c3%a9zier-curve

This could be implemented by calculating the (at maximum 2 vertical and 2 horizontal) extrema of each cubic bezier element. This is a O(1) operation for each segment, as it can be computed directly (roots of quadratic equations). The definition of

\def\pgf@lt@curveto#1#2#3#4#5#6{%
  \pgf@protocolsizes{#1}{#2}%
  \pgf@protocolsizes{#3}{#4}%
  \pgf@protocolsizes{#5}{#6}%
  \pgfsyssoftpath@curveto{\the#1}{\the#2}{\the#3}{\the#4}{\the#5}{\the#6}%
}

has to be changed in such way, that

\pgf@protocolsizes{#3}{#4}%
\pgf@protocolsizes{#5}{#6}%

are replaced by

\pgf@protocolsizes{first horizontal extrema}{first vertical extrema}%
\pgf@protocolsizes{second horizontal extrema}{second vertical extrema}%
hmenke commented 4 years ago

This has been implemented in the new bbox library: #714 https://github.com/pgf-tikz/pgf/commit/334e32e2a3733047d0cc68ebeb2fc96a7b53bdec