Advertisement
Hppavilion1

OCR Matching Language

Apr 12th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. // Note that this uses a traditional, intuitive coordinate system where the origin is at the lower left corner where increasing x goes right, increasing y goes up, rather than that y-is-down bullshit* someone decided computers should use. (*I'm sure there was a very good reason at the time, but seriously?)
  2.  
  3. $maxsep = 4px; // Defines the maximum separation that can be considered "near", or more accurately the variable used for that.
  4.  
  5. pred __near_boundary_point__[null](pnt, from) := sqrt((from.x-pnt.x^2)+(from.y-pnt.y)^2) <= $maxsep; // One colon; defines that a point is considered "NEAR" to another (without modifiers, hence the "null"; if it was something else it would define a different type of nearness) if it is within 4px away, based on the standard (Pythagorean) distance formula
  6.  
  7. pred __near_boundary_num__(num, rel) := abs(num-rel) <= $maxsep // The [null] can be implicit; it was used above for the sole purpose of clarity that alternative nearness can be used.
  8.  
  9. baseline ::= LINE ALONG y = 0; // The baseline is at the bottom of the document
  10. topline ::= LINE ALONG y=16; // Letters are 16 pixels tall
  11. letter['LATIN CAPITAL LETTER A'] ::= // The capital "A" character; moves along
  12. left_ln:=(LINE FROM (start_x, start_y) NEAR baseline TO (peak_x, peak_y) NEAR topline),
  13. right_ln:=(LINE FROM NEAR (peak_x, peak_y) TO (NEAR start_x+12, NEAR start_y)), // The right down-sloping line ends roughly 3/4 of the height left of the left up-sloping line
  14. cross_ln:=LINE FROM (NEAR left_ln.x_at(cross_y1), cross_y1:=(NEAR 10px)) TO (NEAR right_ln.x_at(cross_y2), cross_y2:=(NEAR 10px)); // Here we see algebraic matching; allows a variable number to be used, then that number to be used again somewhere else.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement