MCPcopy Create free account
hub / github.com/creatale/node-dv / ComputeDirection

Function ComputeDirection

deps/tesseract/classify/mfoutline.cpp:400–452  ·  view source on GitHub ↗

* This routine computes the slope from Start to Finish and * and then computes the approximate direction of the line * segment from Start to Finish. The direction is quantized * into 8 buckets: * N, S, E, W, NE, NW, SE, SW * Both the slope and the direction are then stored into * the appropriate fields of the Start edge point. The * direction is also stored into the PreviousDirection fie

Source from the content-addressed store, hash-verified

398 * @note History: 7/25/89, DSJ, Created.
399 */
400void ComputeDirection(MFEDGEPT *Start,
401 MFEDGEPT *Finish,
402 FLOAT32 MinSlope,
403 FLOAT32 MaxSlope) {
404 FVECTOR Delta;
405
406 Delta.x = Finish->Point.x - Start->Point.x;
407 Delta.y = Finish->Point.y - Start->Point.y;
408 if (Delta.x == 0)
409 if (Delta.y < 0) {
410 Start->Slope = -MAX_FLOAT32;
411 Start->Direction = south;
412 }
413 else {
414 Start->Slope = MAX_FLOAT32;
415 Start->Direction = north;
416 }
417 else {
418 Start->Slope = Delta.y / Delta.x;
419 if (Delta.x > 0)
420 if (Delta.y > 0)
421 if (Start->Slope > MinSlope)
422 if (Start->Slope < MaxSlope)
423 Start->Direction = northeast;
424 else
425 Start->Direction = north;
426 else
427 Start->Direction = east;
428 else if (Start->Slope < -MinSlope)
429 if (Start->Slope > -MaxSlope)
430 Start->Direction = southeast;
431 else
432 Start->Direction = south;
433 else
434 Start->Direction = east;
435 else if (Delta.y > 0)
436 if (Start->Slope < -MinSlope)
437 if (Start->Slope > -MaxSlope)
438 Start->Direction = northwest;
439 else
440 Start->Direction = north;
441 else
442 Start->Direction = west;
443 else if (Start->Slope > MinSlope)
444 if (Start->Slope < MaxSlope)
445 Start->Direction = southwest;
446 else
447 Start->Direction = south;
448 else
449 Start->Direction = west;
450 }
451 Finish->PreviousDirection = Start->Direction;
452}
453
454/**
455 * This routine returns the next point in the micro-feature

Callers 1

FindDirectionChangesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected