Commit 8ee1c73b authored by Paul Asmuth's avatar Paul Asmuth
Browse files

remove the vec2_ function name prefixes

parent 94d6fe0f
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -26,15 +26,15 @@ ReturnCode arrow_draw_default(
    const Measure& size,
    const Color& color,
    Page* layer) {
  auto direction = vec2_normalize(vec2_sub(to, from));
  auto direction = normalize(sub(to, from));
  auto ortho = vec2{direction.y, direction.x * -1};

  double head_width_factor = 2;
  double head_length_factor = 4;
  Path head_path;
  head_path.moveTo(vec2_add(to, vec2_mul(ortho, size * head_width_factor)));
  head_path.lineTo(vec2_sub(to, vec2_mul(ortho, size * head_width_factor)));
  head_path.lineTo(vec2_add(to, vec2_mul(direction, size * head_length_factor)));
  head_path.moveTo(add(to, mul(ortho, size * head_width_factor)));
  head_path.lineTo(sub(to, mul(ortho, size * head_width_factor)));
  head_path.lineTo(add(to, mul(direction, size * head_length_factor)));
  head_path.closePath();

  StrokeStyle line_style;
+2 −2
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ ReturnCode font_get_glyph_path(

        c.points.insert(
            c.points.begin() + i + 1,
            vec2_mul(vec2_add(c.points[i + 0], c.points[i + 1]), 0.5));
            mul(add(c.points[i + 0], c.points[i + 1]), 0.5));
      }
    }

@@ -163,7 +163,7 @@ ReturnCode font_get_glyph_path(
        c.tags.back() == GlyphPointType::OFF2) {
      c.points.insert(
          c.points.begin(),
          vec2_mul(vec2_add(c.points.front(), c.points.back()), 0.5));
          mul(add(c.points.front(), c.points.back()), 0.5));

      c.tags.insert(c.tags.begin(), GlyphPointType::ON);
    }
+6 −6
Original line number Diff line number Diff line
@@ -22,13 +22,13 @@ bool intersect_line_line(
    vec2 v1,
    vec2* p /* = nullptr */) {
  // ensure the direction vectors are normalized
  v0 = vec2_normalize(v0);
  v1 = vec2_normalize(v1);
  v0 = normalize(v0);
  v1 = normalize(v1);

  // consider lines as parallel if the angle between them is smaller than some
  // threshold
  const double a_epsilon = 0.001;
  double a = acos(vec2_dot(v0, v1));
  double a = acos(dot(v0, v1));
  double a_norm = fmod(M_PI - a, M_PI);

  if (a_norm < a_epsilon) {
@@ -101,7 +101,7 @@ bool intersect_line_lineseg(
      p0,
      v0,
      s1,
      vec2_normalize(vec2_sub(e1, s1)),
      normalize(sub(e1, s1)),
      &pt);

  if (!pt_exists) {
@@ -137,9 +137,9 @@ bool intersect_lineseg_lineseg(
  vec2 pt;
  auto pt_exists = intersect_line_line(
      s0,
      vec2_sub(e0, s0),
      sub(e0, s0),
      s1,
      vec2_normalize(vec2_sub(e1, s1)),
      normalize(sub(e1, s1)),
      &pt);

  if (!pt_exists) {
+6 −6
Original line number Diff line number Diff line
@@ -22,9 +22,9 @@ Path shape_hatch(
    double offset,
    double stride,
    double width) {
  auto origin = vec2_mean(clip.vertices.data(), clip.vertices.size());
  auto direction = vec2_from_deg(angle_deg);
  auto ortho = vec2_from_deg(angle_deg + 90);
  auto origin = mean(clip.vertices.data(), clip.vertices.size());
  auto direction = from_deg(angle_deg);
  auto ortho = from_deg(angle_deg + 90);

  Path p;
  for (size_t i = 0; ; ++i) {
@@ -39,13 +39,13 @@ Path shape_hatch(
      //   - a "bottom" line that is offset by half the width in the other direction
      intersect_poly_line(
          clip,
          vec2_add(origin, vec2_mul(ortho, i * s * stride + offset + width * 0.5)),
          add(origin, mul(ortho, i * s * stride + offset + width * 0.5)),
          direction,
          &vertices);

      intersect_poly_line(
          clip,
          vec2_add(origin, vec2_mul(ortho, i * s * stride + offset + width * -0.5)),
          add(origin, mul(ortho, i * s * stride + offset + width * -0.5)),
          direction,
          &vertices);

@@ -63,7 +63,7 @@ Path shape_hatch(

      // build a simple polygon from the resulting points by connecting them
      // in clockwise order
      vec2_sort_cw(vertices.data(), vertices.size());
      sort_cw(vertices.data(), vertices.size());

      for (size_t i = 0; i < vertices.size(); ++i) {
        if (i == 0) {
+17 −17
Original line number Diff line number Diff line
@@ -33,58 +33,58 @@ double vec2_magnitude(const vec2& v) {
  return sqrt(v.x * v.x + v.y * v.y);
}

vec2 vec2_normalize(const vec2& v) {
vec2 normalize(const vec2& v) {
  auto m = vec2_magnitude(v);
  return {v.x / m, v.y / m};
}

vec2 vec2_add(const vec2& a, const vec2& b) {
vec2 add(const vec2& a, const vec2& b) {
  return {a.x + b.x, a.y + b.y};
}

vec2 vec2_sub(const vec2& a, const vec2& b) {
vec2 sub(const vec2& a, const vec2& b) {
  return {a.x - b.x, a.y - b.y};
}

vec2 vec2_mul(const vec2& v, double s) {
vec2 mul(const vec2& v, double s) {
  return {v.x * s, v.y * s};
}

double vec2_dot(const vec2& a, const vec2& b) {
double dot(const vec2& a, const vec2& b) {
  return a.x * b.x + a.y * b.y;
}

vec2 vec2_from_deg(double deg) {
vec2 from_deg(double deg) {
  double a = -deg / 180.0 * M_PI;
  return {cos(a), sin(a)};
}

vec2 vec2_mean(const vec2* v, size_t v_len) {
vec2 mean(const vec2* v, size_t v_len) {
  vec2 m;

  for (size_t i = 0; i < v_len; ++i) {
    m = vec2_add(m, v[i]);
    m = add(m, v[i]);
  }

  return vec2_mul(m, 1.0 / v_len);
  return mul(m, 1.0 / v_len);
}

void vec2_sort_cw(vec2* v, size_t v_len) {
  auto m = vec2_mean(v, v_len);
void sort_cw(vec2* v, size_t v_len) {
  auto m = mean(v, v_len);

  std::sort(v, v + v_len, [&m] (const auto& a, const auto& b) {
    auto da = vec2_sub(a, m);
    auto db = vec2_sub(b, m);
    auto da = sub(a, m);
    auto db = sub(b, m);
    return atan2(db.y, db.x) < atan2(da.y, da.x);
  });
}

void vec2_sort_ccw(vec2* v, size_t v_len) {
  auto m = vec2_mean(v, v_len);
void sort_ccw(vec2* v, size_t v_len) {
  auto m = mean(v, v_len);

  std::sort(v, v + v_len, [&m] (const auto& a, const auto& b) {
    auto da = vec2_sub(a, m);
    auto db = vec2_sub(b, m);
    auto da = sub(a, m);
    auto db = sub(b, m);
    return atan2(da.y, da.x) < atan2(db.y, db.x);
  });
}
Loading