Class: QrForge::Components::EyeOuter::Circle

Inherits:
ForgeComponent show all
Defined in:
lib/qr_forge/components/eye_outer/circle.rb

Constant Summary collapse

DEFAULT_STROKE_WIDTH =
1.0

Instance Method Summary collapse

Methods inherited from ForgeComponent

#initialize

Constructor Details

This class inherits a constructor from QrForge::Components::ForgeComponent

Instance Method Details

#draw(y:, x:, quiet_zone:, area:, color: "black", **_) ⇒ Object

Draws a circle that fills the full ‘area’ box, inset by half the stroke so it never overlaps the modules beneath.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/qr_forge/components/eye_outer/circle.rb', line 12

def draw(y:, x:, quiet_zone:, area:, color: "black", **_)
  stroke_width = DEFAULT_STROKE_WIDTH

  # Radius = (full width of box – one stroke) / 2
  r = (area - stroke_width) / 2.0

  # Center of the N×N box (plus quiet_zone offset)
  cx = x + quiet_zone + (area / 2.0)
  cy = y + quiet_zone + (area / 2.0)

  @xml_builder.circle(
    cx: cx,
    cy: cy,
    r: r,
    "stroke-width": stroke_width,
    stroke: color,
    fill: "transparent",
    test_id: @test_id
  )
end