﻿using System;

namespace Grobid.PdfToXml
{
    public static class Extensions
    {
        // Same rules as pdftoxml.

        // Max difference in primary font sizes on two lines in the same
        // block.  Delta1 is used when examining new lines above and below the
        // current block.
        private const double maxBlockFontSizeDelta1 = 0.05;

        // Max distance between baselines of two lines within a block, as a
        // fraction of the font size.
        private const double maxLineSpacingDelta = 1.5;

        public static bool IsSameBlock(this TextBlock prevTextBlock, TextBlock currTextBlock)
        {
            bool isSimilarLineHeight = currTextBlock.Y + currTextBlock.Height >= prevTextBlock.Y;
            bool isSimilarFontSize = Math.Abs(currTextBlock.TokenBlocks[0].FontSize - prevTextBlock.TokenBlocks[0].FontSize) <
                                     (currTextBlock.TokenBlocks[0].FontSize * Extensions.maxBlockFontSizeDelta1);
            bool isMinimalSpacing = (currTextBlock.Y - prevTextBlock.Y) < (prevTextBlock.TokenBlocks[0].FontSize * Extensions.maxLineSpacingDelta);

            return (isSimilarLineHeight && isSimilarFontSize && isMinimalSpacing);
        }
    }
}
Move extensions to appropriate project
Move extensions to appropriate project
