1 /****************************************************************************** 2 * 3 * File: outlines.h 4 * Description: Combinatorial Splitter 5 * Author: Mark Seaman, OCR Technology 6 * 7 * (c) Copyright 1989, Hewlett-Packard Company. 8 ** Licensed under the Apache License, Version 2.0 (the "License"); 9 ** you may not use this file except in compliance with the License. 10 ** You may obtain a copy of the License at 11 ** http://www.apache.org/licenses/LICENSE-2.0 12 ** Unless required by applicable law or agreed to in writing, software 13 ** distributed under the License is distributed on an "AS IS" BASIS, 14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 ** See the License for the specific language governing permissions and 16 ** limitations under the License. 17 * 18 *****************************************************************************/ 19 20 #ifndef OUTLINES_H 21 #define OUTLINES_H 22 23 #include <cmath> // for abs 24 #include "blobs.h" // for TPOINT 25 #include "params.h" // for IntParam 26 #include "wordrec.h" // for Wordrec 27 28 /*---------------------------------------------------------------------- 29 C o n s t a n t s 30 ----------------------------------------------------------------------*/ 31 #define LARGE_DISTANCE 100000 /* Used for closest dist */ 32 #define MIN_BLOB_SIZE 10 /* Big units */ 33 #define MAX_ASPECT_RATIO 2.5 /* Widest character */ 34 35 /*---------------------------------------------------------------------- 36 M a c r o s 37 ----------------------------------------------------------------------*/ 38 /********************************************************************** 39 * same_point 40 * 41 * Return true if the point values are the same. The parameters must 42 * be of type POINT. 43 **********************************************************************/ 44 #define same_point(p1, p2) \ 45 ((abs(p1.x - p2.x) < chop_same_distance) && (abs(p1.y - p2.y) < chop_same_distance)) 46 47 /********************************************************************** 48 * dist_square 49 * 50 * Return the square of the distance between these two points. The 51 * parameters must be of type POINT. 52 **********************************************************************/ 53 54 #define dist_square(p1, p2) ((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y)) 55 56 /********************************************************************** 57 * closest 58 * 59 * The expression provides the EDGEPT that is closest to the point in 60 * question. All three parameters must be of type EDGEPT. 61 **********************************************************************/ 62 63 #define closest(test_p, p1, p2) \ 64 (p1 ? (p2 ? ((dist_square(test_p->pos, p1->pos) < dist_square(test_p->pos, p2->pos)) ? p1 : p2) \ 65 : p1) \ 66 : p2) 67 68 /********************************************************************** 69 * edgept_dist 70 * 71 * Return the distance (squared) between the two edge points. 72 **********************************************************************/ 73 74 #define edgept_dist(p1, p2) (dist_square((p1)->pos, (p2)->pos)) 75 76 /********************************************************************** 77 * is_exterior_point 78 * 79 * Return true if the point supplied is an exterior projection from the 80 * outline. 81 **********************************************************************/ 82 83 #define is_exterior_point(edge, point) \ 84 (same_point(edge->prev->pos, point->pos) || same_point(edge->next->pos, point->pos) || \ 85 (angle_change(edge->prev, edge, edge->next) - angle_change(edge->prev, edge, point) > 20)) 86 87 /********************************************************************** 88 * is_equal 89 * 90 * Return true if the POINTs are equal. 91 **********************************************************************/ 92 93 #define is_equal(p1, p2) (((p1).x == (p2).x) && ((p1).y == (p2).y)) 94 95 /********************************************************************** 96 * is_on_line 97 * 98 * Return true if the point is on the line segment between the two end 99 * points. The two end points are included as part of the line. The 100 * parameters must be of type POINT. 101 **********************************************************************/ 102 103 #define is_on_line(p, p0, p1) \ 104 (within_range((p).x, (p0).x, (p1).x) && within_range((p).y, (p0).y, (p1).y)) 105 106 /********************************************************************** 107 * within_range 108 * 109 * Return true if the first number is in between the second two numbers. 110 * Return false otherwise. 111 **********************************************************************/ 112 113 #define within_range(x, x0, x1) (((x0 <= x) && (x <= x1)) || ((x1 <= x) && (x <= x0))) 114 115 #endif 116