   }
 }
 
-void draw_double_border(void) {
+void draw_double_border(vec2 localPos) {
+  float pixelsPerFragment = length(fwidth(localPos.xy));
   switch (vBorderPart) {
     // These are the layer tile part PrimitivePart as uploaded by the tiling.rs
     case PST_TOP_LEFT:

  return mix(white, circleColor, circleColor.a);
}

vec4 draw_double_edge(float pos, float len) {
  // Devided border to 3 parts, draw color on first and third part,
  // leave second part blank.
  float one_third_len = len / 3.0;

  float in_first_part = step(pos, one_third_len);
  float in_third_part = step(len - one_third_len, pos);

  // The result of this should be 1.0 if we're in the 1st or 3rd part.
  // And 0.0 for the blank part.
  float should_fill = in_first_part + in_third_part;

  // This is the conversion factor for transformations and device pixel scaling.
  float pixels_per_fragment = length(fwidth(vLocalPos.xy));
  vec4 white = vec4(1.0, 1.0, 1.0, 1.0);
  return mix(white, get_fragment_color(vDistanceFromMixLine, pixels_per_fragment), should_fill);
}

vec4 draw_double_edge_vertical() {
  // Get our position within this specific segment
  float position = vLocalPos.x - vLocalRect.x;
  return draw_double_edge(position, vLocalRect.z);
}

vec4 draw_double_edge_horizontal() {
  // Get our position within this specific segment
  float position = vLocalPos.y - vLocalRect.y;
  return draw_double_edge(position, vLocalRect.w);
}

vec4 draw_double_edge_with_radius() {
  // Get our position within this specific segment
  float position = distance(vRefPoint, vLocalPos) - vRadii.z;
  float len = vRadii.x - vRadii.z;
  return draw_double_edge(position, len);
}

vec4 draw_double_edge_corner() {
  if (vRadii.x > 0) {
    return draw_double_edge_with_radius();
  }

  bool is_vertical = (vBorderPart == PST_TOP_LEFT) ? vDistanceFromMixLine < 0 :
                                                     vDistanceFromMixLine >= 0;
  if (is_vertical) {
    return draw_double_edge_vertical();
  } else {
    return draw_double_edge_horizontal();
  }
}


  // it between the limits accepted by `mix`.
  float colorMix = min(max(distanceFromMixLine / pixelsPerFragment, -0.5), 0.5) + 0.5;
  return mix(vHorizontalColor, vVerticalColor, colorMix);
}

float alpha_for_solid_border(float distance_from_ref,
                             float inner_radius,
                             float outer_radius,
                             float pixels_per_fragment) {
  // We want to start anti-aliasing one pixel in from the border.
  float nudge = 1 * pixels_per_fragment;
  inner_radius += nudge;
  outer_radius -= nudge;

  if ((distance_from_ref < outer_radius && distance_from_ref > inner_radius)) {
    return 1.0;
  }

  float distance_from_border = max(distance_from_ref - outer_radius,
                                   inner_radius - distance_from_ref);

  // Move the distance back into pixels.
  distance_from_border /= pixels_per_fragment;

  // Apply a more gradual fade out to transparent.
  distance_from_border -= 0.5;

  return smoothstep(1.0, 0, distance_from_border);
}

float alpha_for_solid_border_corner(vec2 local_pos,
                                    float inner_radius,
                                    float outer_radius,
                                    float pixels_per_fragment) {
  float distance_from_ref = distance(vRefPoint, local_pos);
  return alpha_for_solid_border(distance_from_ref, inner_radius, outer_radius, pixels_per_fragment);
}

#ifdef WR_FEATURE_TRANSFORM
