Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Pseudocode for checking if there is a large gap between the
// current and next candidate's bounding box.
var isNextItemOnNewParagraph: Bool {
let avgHeight = (currentObservationCandidateHeight + currentObservationCandidateHeight / 2)
let currentItemHeight = currentObservationCandidateHeight
let nextItemHeight = currentObservationCandidateHeight
let isSeparationLargerThanCurrentItemHeight = avgHeight >= currentItemHeight
let isSeparationLargerThanNextItemHeight = avgHeight >= nextItemHeight
return isSeparationLargerThanCurrentItemHeight || isSeparationLargerThanNextItemHeight
// Pseudocode for checking if next candidate is on a new line and is there
// an indentation for the next candidate.
let isNextItemOnNewLine = avgBottomYOfNextItem > avgBottomYOfCurrentItem
if isNextItemOnNewParagraph {
} else if isNextItemOnNewLine {
let nextItemTopLeftX = nextItemTopLeftXPosition
let minimumParagraphXposition = aParagraphMinX
let isNextItemPartOfCurrentParagraph = nextItemTopLeftX <= minimumParagraphXposition
// Assumption: if there is no sufficient gap between paragraphs then new paragraphs
// are started with an indentation
if isNextItemPartOfCurrentParagraph {
updateMinimumXPositionOfAParagraphs(with: nextItemTopLeftX)
} else {
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment