<html>
    <head>
      <base href="https://bugs.documentfoundation.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Create and use a dedicated Length C++ type"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=138109">138109</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Create and use a dedicated Length C++ type
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>LibreOffice
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>UNCONFIRMED
          </td>
        </tr>

        <tr>
          <th>Keywords</th>
          <td>difficultyMedium, easyHack, skillCpp
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LibreOffice
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>libreoffice-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mikekaganski@hotmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>caolanm@redhat.com, michael.stahl@cib.de, quikee@gmail.com, sbergman@redhat.com, vmiklos@collabora.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We use length measures intensively throughout the codebase. We use millimeters,
inches, hundreds of mm, cm, m, twips, points, EMUs, and many others. We convert
those in all directions.

I suggest to create a dedicated class (in tools?) that would represent generic
length; consistently using such class in the code would allow to minimize
rounding errors from repeated conversions (there should ideally be only two
conversions: when a length is read from a file, and when it's output), and
prevent confusion when a number (representing a length) is received from some
function, and it's hard to know what units should be used with the number.

It possibly should use some fixed internal unit for length, and some fixed type
for the value. It should provide convenience static and member functions for
conversion to/from different units, which would also provide overloads for
different resulting typed (esp. to differentiate floating-point results vs
integer results, with rounding for the latter). It should also provide
user-defined literals for simplifying definitions of things like 2_mm or
25_EMU. It needs to allow usual arithmetical operations.

Subject to discussion, I propose to use mm100 as the class' base units, and
double as the type for the stored value. That allows to represent any whole
number of mm100s up to 2^53 (i.e., up to 90 071 992 547 meters); it will also
allow to unambiguously represent any reasonable whole value in EMUs (greater
than 20 million meters).

The task would be first to create such a class, and start using it; then
gradually make more and more code use it, passing it around, and avoid
conversions except in places of input and output.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>