From d0cb6c0e924586fe96205c29b7780014644820a4 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Mon, 18 Apr 2016 13:07:53 -0700 Subject: [PATCH] Replace private hypotenuse formula with hypot() --- ocrmypdf/pageinfo.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ocrmypdf/pageinfo.py b/ocrmypdf/pageinfo.py index 301866da..a6e13aaf 100644 --- a/ocrmypdf/pageinfo.py +++ b/ocrmypdf/pageinfo.py @@ -3,6 +3,7 @@ from subprocess import Popen, PIPE from decimal import Decimal, getcontext +from math import hypot import re import sys import PyPDF2 as pypdf @@ -72,9 +73,6 @@ def _shorthand_from_matrix(matrix): return tuple(map(float, (a, b, c, d, e, f))) -def euclidean_distance(rowvec1, rowvec2): - return ((rowvec1[0] - rowvec2[0]) ** 2 - + (rowvec1[1] - rowvec2[1]) ** 2) ** 0.5 ContentsInfo = namedtuple('ContentsInfo', @@ -160,8 +158,8 @@ def _get_dpi(ctm_shorthand, image_size): a, b, c, d, _, _ = ctm_shorthand # Calculate the width and height of the image in PDF units - image_drawn_width = (a**2 + b**2) ** 0.5 - image_drawn_height = (c**2 + d**2) ** 0.5 + image_drawn_width = hypot(a, b) + image_drawn_height = hypot(c, d) # The scale of the image is pixels per PDF unit (1/72") scale_w = image_size[0] / image_drawn_width