Commit a223c148 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add the 'plot/rectangles' element

parent 8999f894
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "elements/plot/labels.h"
#include "elements/plot/lines.h"
#include "elements/plot/points.h"
#include "elements/plot/rectangles.h"
#include "elements/plot/vectors.h"
#include "elements/chart/linechart.h"
#include "elements/chart/scatterplot.h"
@@ -66,6 +67,7 @@ ReturnCode environment_setup_defaults(Environment* env) {
  element_bind(elems, "plot/labels", bind(elements::plot::labels::build, _1, _2, _3));
  element_bind(elems, "plot/lines", bind(elements::plot::lines::build, _1, _2, _3));
  element_bind(elems, "plot/points", bind(elements::plot::points::build, _1, _2, _3));
  element_bind(elems, "plot/rectangles", bind(elements::plot::rectangles::build, _1, _2, _3));
  element_bind(elems, "plot/vectors", bind(elements::plot::vectors::build, _1, _2, _3));
  element_bind(elems, "legend", bind(elements::legend::build, _1, _2, _3));
  element_bind(elems, "legend/item", bind(elements::legend::item::build, _1, _2, _3));
+8 −0
Original line number Diff line number Diff line
@@ -126,6 +126,14 @@ void convert_units(
  }
}

void convert_unit(
    const std::vector<UnitConverter>& converters,
    Measure* measure) {
  for (const auto& c : converters) {
    c(measure);
  }
}

void convert_unit_typographic(
    double dpi,
    Measure font_size,
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,10 @@ Measure measure_or(const Measure& primary, const Measure& fallback);

using UnitConverter = std::function<void (Measure*)>;

void convert_unit(
    const std::vector<UnitConverter>& converters,
    Measure* measure);

void convert_units(
    const std::vector<UnitConverter>& converters,
    Measure* begin,
+21 −0
Original line number Diff line number Diff line
@@ -210,6 +210,27 @@ Path path_transform(const Path& path, const mat3& transform) {
  return path_out;
}

void path_add_rectangle(Path* path, vec2 origin, vec2 size) {
  path->moveTo(
      origin.x + size.x / 2,
      origin.y + size.y / 2);

  path->lineTo(
      origin.x + size.x / 2,
      origin.y - size.y / 2);

  path->lineTo(
      origin.x - size.x / 2,
      origin.y - size.y / 2);

  path->lineTo(
      origin.x - size.x / 2,
      origin.y + size.y / 2);

  path->closePath();
}


void path_add_circle(Path* path, vec2 origin, double radius) {
  const double control_point_distance = 0.552284749831;

+6 −1
Original line number Diff line number Diff line
@@ -84,7 +84,12 @@ Path path_from_polygon(const Polygon2& poly);
Path path_transform(const Path& p, const mat3& t);

/**
 * Add a circle to a path
 * Add a rectangle to the path. Origin is the center of the rectangle.
 */
void path_add_rectangle(Path* path, vec2 origin, vec2 size);

/**
 * Add a circle to a path. Origin is the center of the circle.
 */
void path_add_circle(Path* path, vec2 origin, double radius);

Loading