Discussing the article: "Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 2): Points, Contours and the Path"

 

Check out the new article: Creating a Cairo-Inspired Graphics Library for MetaTrader 5 (Part 2): Points, Contours and the Path.

This second part adds the geometry layer to a Cairo‑inspired graphics library for MetaTrader 5. It defines a path of double‑precision points grouped into contours, records open/closed intent, and stores vertices in a flat array with start indices. We implement MoveTo, LineTo, Close, provide basic shape helpers, and include a demo that visualizes the built geometry for inspection and reuse.

The staircase in Part 1 resulted from the binary rendering approach and the loss of sub-pixel information.

In the first panel, the edge lies exactly on a pixel boundary, so integer storage loses no information. In the second, the original position is 10.35, but integer storage removes the fractional part. As a result, the renderer receives the same stored coordinate in both cases and cannot distinguish between them. The third panel preserves the coordinate as a double, allowing column 10 to retain its fractional coverage and the rendered edge to match the geometry.

This has two practical consequences:

  • Quality. Anti-aliasing is built entirely out of these fractions. With integers there is nothing to anti-alias, because there is no fraction left to work with.
  • Motion. A widget animating across a panel moves by fractions of a pixel per frame. With integer coordinates it can only jump from one whole pixel to the next, and the eye reads that as judder. With doubles it glides, because the boundary pixels change shade smoothly between whole-pixel steps.

Even a complex icon may contain thousands of points, while the geometry remains small compared with the pixel buffer used to render the panel.

Curves provide another reason to preserve floating-point coordinates. When a curve is flattened into straight segments, its vertices land at fractional positions (eg, 12.3719…, not 12). If the point type could not store those values, curves would be quantized to whole pixels before drawing, and anti-aliasing would not be able to compensate.

Author: Sandro Begashvili