1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - PRC - include
3 File: prc/common.h
4
5 Copyright 2003-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifndef NITRO_PRC_COMMON_H_
19 #define NITRO_PRC_COMMON_H_
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include <nitro/misc.h>
26 #include <nitro/types.h>
27
28 #include <nitro/prc/types.h>
29 #include <nitro/fx/fx_cp.h>
30 #include <nitro/fx/fx_trig.h>
31
32 /*===========================================================================*
33 Constant Definitions
34 *===========================================================================*/
35
36 /*===========================================================================*
37 Type Definitions
38 *===========================================================================*/
39
40
41 /*===========================================================================*
42 Function Declarations
43 *===========================================================================*/
44
45 /*---------------------------------------------------------------------------*
46 Name: PRCi_Init
47
48 Description: Initializes pattern recognition API.
49 Called first from initialization routines in each algorithm.
50
51 Arguments: None.
52
53 Returns: None.
54 *---------------------------------------------------------------------------*/
55 void PRCi_Init(void);
56
57 /*---------------------------------------------------------------------------*
58 Name: PRC_GetEntryStrokes
59
60 Description: Gets dot sequence data from sample DB and sample DB entry.
61
62 Arguments: strokes: Obtained dot sequence data
63 Overwriting is not permitted.
64 prototypeList: sample pattern list
65 entry: sample DB entry
66
67 Returns: None.
68 *---------------------------------------------------------------------------*/
69 void
70
71 PRC_GetEntryStrokes(PRCStrokes *strokes,
72 const PRCPrototypeList *prototypeList, const PRCPrototypeEntry *entry);
73
74 /*---------------------------------------------------------------------------*
75 Name: PRC_CopyStrokes
76
77 Description: Deep copies dot sequence data.
78
79 Arguments: srcStrokes The PRC_Strokes structure to copy from
80 dstStrokes: The copy destination PRC_Strokes structure.
81
82 Returns: If copy worked, TRUE.
83 *---------------------------------------------------------------------------*/
84 BOOL PRC_CopyStrokes(const PRCStrokes *srcStrokes, PRCStrokes *dstStrokes);
85
86 /*===========================================================================*
87 Inline Functions
88 *===========================================================================*/
89
90 /*---------------------------------------------------------------------------*
91 Name: PRC_GetEntryCode
92
93 Description: Returns the code number corresponding to the sample DB entry.
94
95 Arguments: entry: sample DB entry
96
97 Returns: code number
98 *---------------------------------------------------------------------------*/
PRC_GetEntryCode(const PRCPrototypeEntry * entry)99 static inline int PRC_GetEntryCode(const PRCPrototypeEntry *entry)
100 {
101 return (entry != NULL) ? entry->code : -1;
102 }
103
104 /*---------------------------------------------------------------------------*
105 Name: PRC_GetEntryData
106
107 Description: Returns user data associated with the sample DB entry.
108
109 Arguments: entry: sample DB entry
110
111 Returns: User data
112 *---------------------------------------------------------------------------*/
PRC_GetEntryData(const PRCPrototypeEntry * entry)113 static inline void *PRC_GetEntryData(const PRCPrototypeEntry *entry)
114 {
115 return (entry != NULL) ? entry->data : NULL;
116 }
117
118 /*---------------------------------------------------------------------------*
119 Name: PRC_InitStrokes
120
121 Description: Initializes PRCStrokes structure.
122
123 Arguments: strokes: Initialization target.
124 points: Pointer to PRCPoint array which becomes actual memory region.
125 size: Size of array
126
127 Returns: None.
128 *---------------------------------------------------------------------------*/
PRC_InitStrokes(PRCStrokes * strokes,PRCPoint * points,u32 size)129 static inline void PRC_InitStrokes(PRCStrokes *strokes, PRCPoint *points, u32 size)
130 {
131 SDK_ASSERT(strokes && points);
132 strokes->points = points;
133 strokes->capacity = size;
134 strokes->size = 0;
135 }
136
137 /*---------------------------------------------------------------------------*
138 Name: PRC_AppendPoint
139
140 Description: Adds dots to PRCStrokes.
141
142 Arguments: strokes: target.
143 x, y: Points to add.
144
145 Returns: None.
146 *---------------------------------------------------------------------------*/
PRC_AppendPoint(PRCStrokes * strokes,int x,int y)147 static inline void PRC_AppendPoint(PRCStrokes *strokes, int x, int y)
148 {
149 SDK_ASSERT(strokes);
150 SDK_ASSERT(strokes->size < strokes->capacity);
151 strokes->points[strokes->size].x = (s16)x;
152 strokes->points[strokes->size].y = (s16)y;
153 (strokes->size)++;
154 }
155
156 /*---------------------------------------------------------------------------*
157 Name: PRC_AppendPenUpMarker
158
159 Description: Adds marker that means stylus up to PRCStrokes.
160
161 Arguments: strokes: target.
162
163 Returns: None.
164 *---------------------------------------------------------------------------*/
PRC_AppendPenUpMarker(PRCStrokes * strokes)165 static inline void PRC_AppendPenUpMarker(PRCStrokes *strokes)
166 {
167 PRC_AppendPoint(strokes, PRC_PEN_UP_MARKER_X, PRC_PEN_UP_MARKER_Y);
168 }
169
170 /*---------------------------------------------------------------------------*
171 Name: PRC_Clear
172
173 Description: Empties PRCStrokes.
174
175 Arguments: strokes: target.
176
177 Returns: None.
178 *---------------------------------------------------------------------------*/
PRC_Clear(PRCStrokes * strokes)179 static inline void PRC_Clear(PRCStrokes *strokes)
180 {
181 SDK_ASSERT(strokes);
182 strokes->size = 0;
183 }
184
185 /*---------------------------------------------------------------------------*
186 Name: PRC_IsFull
187
188 Description: Determines if PRCStrokes is full.
189
190 Arguments: strokes: target.
191
192 Returns: If full, TRUE.
193 *---------------------------------------------------------------------------*/
PRC_IsFull(const PRCStrokes * strokes)194 static inline BOOL PRC_IsFull(const PRCStrokes *strokes)
195 {
196 SDK_ASSERT(strokes);
197 return strokes->size >= strokes->capacity;
198 }
199
200 /*---------------------------------------------------------------------------*
201 Name: PRC_IsEmpty
202
203 Description: Determines if PRCStrokes is empty or not.
204
205 Arguments: strokes: target.
206
207 Returns: If empty, TRUE.
208 *---------------------------------------------------------------------------*/
PRC_IsEmpty(const PRCStrokes * strokes)209 static inline BOOL PRC_IsEmpty(const PRCStrokes *strokes)
210 {
211 SDK_ASSERT(strokes);
212 return strokes->size == 0;
213 }
214
215 /*---------------------------------------------------------------------------*
216 Name: PRC_IsPenUpMarker
217
218 Description: Determines if marker is one that means stylus up.
219
220 Arguments: point: Target to check.
221
222 Returns: If it is a stylus up marker, TRUE.
223 *---------------------------------------------------------------------------*/
PRC_IsPenUpMarker(const PRCPoint * point)224 static inline int PRC_IsPenUpMarker(const PRCPoint *point)
225 {
226 SDK_ASSERT(point);
227 // If point->x == PRC_PEN_UP_MARKER_X, then point->y==PRC_PEN_UP_MARKER_Y
228 SDK_ASSERT((point->x != PRC_PEN_UP_MARKER_X) || (point->y == PRC_PEN_UP_MARKER_Y));
229 return (point->x == PRC_PEN_UP_MARKER_X);
230 }
231
232 /*---------------------------------------------------------------------------*
233 Name: PRCi_CalcDistance
234
235 Description: Calculates Euclidean distance.
236
237 Arguments: p1, p2: Targets to check.
238
239 Returns: Euclidean distance (fx32).
240 *---------------------------------------------------------------------------*/
PRCi_CalcDistance(const PRCPoint * p1,const PRCPoint * p2)241 static inline fx32 PRCi_CalcDistance(const PRCPoint *p1, const PRCPoint *p2)
242 {
243 SDK_ASSERT(p1 && p2);
244 return (FX_Sqrt
245 (((p1->x - p2->x) * (p1->x - p2->x) +
246 (p1->y - p2->y) * (p1->y - p2->y)) << FX32_SHIFT));
247 }
248
249 /*---------------------------------------------------------------------------*
250 Name: PRCi_CalcAngle
251
252 Description: Calculates an angle.
253
254 Arguments: p1, p2: Targets to check.
255
256 Returns: Angle in (2pi/65536) radian units (u16).
257 *---------------------------------------------------------------------------*/
PRCi_CalcAngle(const PRCPoint * from,const PRCPoint * to)258 static inline u16 PRCi_CalcAngle(const PRCPoint *from, const PRCPoint *to)
259 {
260 SDK_ASSERT(from && to);
261 return ((u16)(FX_Atan2Idx(to->y - from->y, to->x - from->x)));
262 }
263
264
265 #ifdef __cplusplus
266 } /* extern "C" */
267 #endif
268
269 /* NITRO_PRC_COMMON_H_ */
270 #endif
271