Skip to content

Commit ecaad2a

Browse files
committed
ccstruct/werd: Format code with clang-format
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent b1e305f commit ecaad2a

File tree

2 files changed

+182
-209
lines changed

2 files changed

+182
-209
lines changed

src/ccstruct/werd.cpp

+32-50
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: werd.cpp (Formerly word.c)
33
* Description: Code for the WERD class.
44
* Author: Ray Smith
5-
* Created: Tue Oct 08 14:32:12 BST 1991
65
*
76
* (C) Copyright 1991, Hewlett-Packard Ltd.
87
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,18 +16,18 @@
1716
*
1817
**********************************************************************/
1918

19+
#include "werd.h"
2020
#include "helpers.h"
2121
#include "linlsq.h"
22-
#include "werd.h"
2322

2423
// Include automatically generated configuration file if running autoconf.
2524
#ifdef HAVE_CONFIG_H
26-
#include "config_auto.h"
25+
# include "config_auto.h"
2726
#endif
2827

29-
#define FIRST_COLOUR ScrollView::RED ///< first rainbow colour
30-
#define LAST_COLOUR ScrollView::AQUAMARINE ///< last rainbow colour
31-
#define CHILD_COLOUR ScrollView::BROWN ///< colour of children
28+
#define FIRST_COLOUR ScrollView::RED ///< first rainbow colour
29+
#define LAST_COLOUR ScrollView::AQUAMARINE ///< last rainbow colour
30+
#define CHILD_COLOUR ScrollView::BROWN ///< colour of children
3231

3332
const ERRCODE CANT_SCALE_EDGESTEPS =
3433
"Attempted to scale an edgestep format word";
@@ -44,11 +43,8 @@ ELIST2IZE(WERD)
4443
* blank_count blanks in front of the word
4544
* text correct text, outlives this WERD
4645
*/
47-
WERD::WERD(C_BLOB_LIST *blob_list, uint8_t blank_count, const char *text)
48-
: blanks(blank_count),
49-
flags(0),
50-
script_id_(0),
51-
correct(text) {
46+
WERD::WERD(C_BLOB_LIST* blob_list, uint8_t blank_count, const char* text)
47+
: blanks(blank_count), flags(0), script_id_(0), correct(text) {
5248
C_BLOB_IT start_it = &cblobs;
5349
C_BLOB_IT rej_cblob_it = &rej_cblobs;
5450
C_OUTLINE_IT c_outline_it;
@@ -72,17 +68,15 @@ WERD::WERD(C_BLOB_LIST *blob_list, uint8_t blank_count, const char *text)
7268
with the concencus onto the reject list.
7369
*/
7470
start_it.set_to_list(&cblobs);
75-
if (start_it.empty())
76-
return;
71+
if (start_it.empty()) return;
7772
for (start_it.mark_cycle_pt(); !start_it.cycled_list(); start_it.forward()) {
7873
bool reject_blob = false;
7974
bool blob_inverted;
8075

8176
c_outline_it.set_to_list(start_it.data()->out_list());
8277
blob_inverted = c_outline_it.data()->flag(COUT_INVERSE);
8378
for (c_outline_it.mark_cycle_pt();
84-
!c_outline_it.cycled_list() && !reject_blob;
85-
c_outline_it.forward()) {
79+
!c_outline_it.cycled_list() && !reject_blob; c_outline_it.forward()) {
8680
reject_blob = c_outline_it.data()->flag(COUT_INVERSE) != blob_inverted;
8781
}
8882
if (reject_blob) {
@@ -98,35 +92,33 @@ WERD::WERD(C_BLOB_LIST *blob_list, uint8_t blank_count, const char *text)
9892
flags.set_bit(W_INVERSE, (inverted_vote > non_inverted_vote));
9993

10094
start_it.set_to_list(&cblobs);
101-
if (start_it.empty())
102-
return;
95+
if (start_it.empty()) return;
10396
for (start_it.mark_cycle_pt(); !start_it.cycled_list(); start_it.forward()) {
10497
c_outline_it.set_to_list(start_it.data()->out_list());
10598
if (c_outline_it.data()->flag(COUT_INVERSE) != flags.bit(W_INVERSE))
10699
rej_cblob_it.add_after_then_move(start_it.extract());
107100
}
108101
}
109102

110-
111103
/**
112104
* WERD::WERD
113105
*
114106
* Constructor to build a WERD from a list of C_BLOBs.
115107
* The C_BLOBs are not copied so the source list is emptied.
116108
*/
117109

118-
WERD::WERD(C_BLOB_LIST * blob_list, ///< In word order
119-
WERD * clone) ///< Source of flags
120-
: flags(clone->flags),
121-
script_id_(clone->script_id_),
122-
correct(clone->correct) {
110+
WERD::WERD(C_BLOB_LIST* blob_list, ///< In word order
111+
WERD* clone) ///< Source of flags
112+
: flags(clone->flags),
113+
script_id_(clone->script_id_),
114+
correct(clone->correct) {
123115
C_BLOB_IT start_it = blob_list; // iterator
124116
C_BLOB_IT end_it = blob_list; // another
125117

126-
while (!end_it.at_last ())
127-
end_it.forward (); //move to last
128-
(reinterpret_cast<C_BLOB_LIST*>(&cblobs))->assign_to_sublist(&start_it, &end_it);
129-
//move to our list
118+
while (!end_it.at_last()) end_it.forward(); // move to last
119+
(reinterpret_cast<C_BLOB_LIST*>(&cblobs))
120+
->assign_to_sublist(&start_it, &end_it);
121+
// move to our list
130122
blanks = clone->blanks;
131123
// fprintf(stderr,"Wrong constructor!!!!\n");
132124
}
@@ -223,7 +215,6 @@ void WERD::join_on(WERD* other) {
223215
}
224216
}
225217

226-
227218
/**
228219
* WERD::copy_on
229220
*
@@ -285,15 +276,14 @@ void WERD::print() {
285276
tprintf("Script = %d\n", script_id_);
286277
}
287278

288-
289279
/**
290280
* WERD::plot
291281
*
292282
* Draw the WERD in the given colour.
293283
*/
294284

295285
#ifndef GRAPHICS_DISABLED
296-
void WERD::plot(ScrollView *window, ScrollView::Color colour) {
286+
void WERD::plot(ScrollView* window, ScrollView::Color colour) {
297287
C_BLOB_IT it = &cblobs;
298288
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
299289
it.data()->plot(window, colour, colour);
@@ -304,8 +294,7 @@ void WERD::plot(ScrollView *window, ScrollView::Color colour) {
304294
// Get the next color in the (looping) rainbow.
305295
ScrollView::Color WERD::NextColor(ScrollView::Color colour) {
306296
ScrollView::Color next = static_cast<ScrollView::Color>(colour + 1);
307-
if (next >= LAST_COLOUR || next < FIRST_COLOUR)
308-
next = FIRST_COLOUR;
297+
if (next >= LAST_COLOUR || next < FIRST_COLOUR) next = FIRST_COLOUR;
309298
return next;
310299
}
311300

@@ -325,31 +314,28 @@ void WERD::plot(ScrollView* window) {
325314
plot_rej_blobs(window);
326315
}
327316

328-
329317
/**
330318
* WERD::plot_rej_blobs
331319
*
332320
* Draw the WERD rejected blobs in window - ALWAYS GREY
333321
*/
334322

335-
336-
void WERD::plot_rej_blobs(ScrollView *window) {
323+
void WERD::plot_rej_blobs(ScrollView* window) {
337324
C_BLOB_IT it = &rej_cblobs;
338325
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
339326
it.data()->plot(window, ScrollView::GREY, ScrollView::GREY);
340327
}
341328
}
342329
#endif // GRAPHICS_DISABLED
343330

344-
345331
/**
346332
* WERD::shallow_copy()
347333
*
348334
* Make a shallow copy of a word
349335
*/
350336

351-
WERD *WERD::shallow_copy() {
352-
WERD *new_word = new WERD;
337+
WERD* WERD::shallow_copy() {
338+
WERD* new_word = new WERD;
353339

354340
new_word->blanks = blanks;
355341
new_word->flags = flags;
@@ -358,41 +344,37 @@ WERD *WERD::shallow_copy() {
358344
return new_word;
359345
}
360346

361-
362347
/**
363348
* WERD::operator=
364349
*
365350
* Assign a word, DEEP copying the blob list
366351
*/
367352

368-
WERD & WERD::operator= (const WERD & source) {
369-
this->ELIST2_LINK::operator= (source);
353+
WERD& WERD::operator=(const WERD& source) {
354+
this->ELIST2_LINK::operator=(source);
370355
blanks = source.blanks;
371356
flags = source.flags;
372357
script_id_ = source.script_id_;
373358
dummy = source.dummy;
374359
correct = source.correct;
375-
if (!cblobs.empty())
376-
cblobs.clear();
360+
if (!cblobs.empty()) cblobs.clear();
377361
cblobs.deep_copy(&source.cblobs, &C_BLOB::deep_copy);
378362

379-
if (!rej_cblobs.empty())
380-
rej_cblobs.clear();
363+
if (!rej_cblobs.empty()) rej_cblobs.clear();
381364
rej_cblobs.deep_copy(&source.rej_cblobs, &C_BLOB::deep_copy);
382365
return *this;
383366
}
384367

385-
386368
/**
387369
* word_comparator()
388370
*
389371
* word comparator used to sort a word list so that words are in increasing
390372
* order of left edge.
391373
*/
392374

393-
int word_comparator(const void *word1p, const void *word2p) {
394-
const WERD *word1 = *reinterpret_cast<const WERD* const*>(word1p);
395-
const WERD *word2 = *reinterpret_cast<const WERD* const*>(word2p);
375+
int word_comparator(const void* word1p, const void* word2p) {
376+
const WERD* word1 = *reinterpret_cast<const WERD* const*>(word1p);
377+
const WERD* word2 = *reinterpret_cast<const WERD* const*>(word2p);
396378
return word1->bounding_box().left() - word2->bounding_box().left();
397379
}
398380

@@ -475,7 +457,7 @@ WERD* WERD::ConstructWerdWithNewBlobs(C_BLOB_LIST* all_blobs,
475457
TBOX a_blob_box = a_blob->bounding_box();
476458
if ((not_found_box.major_overlap(a_blob_box) ||
477459
a_blob_box.major_overlap(not_found_box)) &&
478-
not_found_box.y_overlap_fraction(a_blob_box) > 0.8) {
460+
not_found_box.y_overlap_fraction(a_blob_box) > 0.8) {
479461
// Already taken care of.
480462
delete not_found_it.extract();
481463
break;

0 commit comments

Comments
 (0)