Class: Arrolio::Harness::PixelDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/harness/pixel_diff.rb

Overview

Visual (pixel-level) PDF comparison. Rasterizes both PDFs via pdftoppm to PNG images, then compares corresponding pages pixel-by-pixel. Reports per-page similarity percentage and an overall score.

Unlike PdfDiff (which compares extracted text), PixelDiff catches visual differences: font spacing, image placement, border alignment, color rendering. Useful for measuring how close Arrolio's visual output is to the reference.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ours_path, theirs_path, dpi: 72) ⇒ PixelDiff

Returns a new instance of PixelDiff.



24
25
26
27
28
# File 'lib/arrolio/harness/pixel_diff.rb', line 24

def initialize(ours_path, theirs_path, dpi: 72)
  @ours_path = ours_path.to_s
  @theirs_path = theirs_path.to_s
  @dpi = dpi.to_i
end

Instance Attribute Details

#dpiObject (readonly)

Returns the value of attribute dpi.



22
23
24
# File 'lib/arrolio/harness/pixel_diff.rb', line 22

def dpi
  @dpi
end

#ours_pathObject (readonly)

Returns the value of attribute ours_path.



22
23
24
# File 'lib/arrolio/harness/pixel_diff.rb', line 22

def ours_path
  @ours_path
end

#theirs_pathObject (readonly)

Returns the value of attribute theirs_path.



22
23
24
# File 'lib/arrolio/harness/pixel_diff.rb', line 22

def theirs_path
  @theirs_path
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/arrolio/harness/pixel_diff.rb', line 30

def call
  ours_imgs = rasterize(@ours_path)
  theirs_imgs = rasterize(@theirs_path)
  return empty_result if ours_imgs.empty? && theirs_imgs.empty?

  per_page = compare_pages(ours_imgs, theirs_imgs)
  overall = per_page.sum / [per_page.length, 1].max
  Result.new(
    ours_pages: ours_imgs.length,
    theirs_pages: theirs_imgs.length,
    per_page_similarity: per_page,
    overall_similarity: overall
  )
end