-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShuffler.cpp
More file actions
75 lines (66 loc) · 2.2 KB
/
Copy pathShuffler.cpp
File metadata and controls
75 lines (66 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Shuffler.cpp
* xwall
*
* Created by Tim Medcalf on 19/10/2010.
* Copyright 2010 ErgoThis Ltd. All rights reserved.
*
*/
#include "Shuffler.h"
#include "Global.h"
#include "CloudWord.h"
#include "iostream"
using namespace std;
void Shuffler::shuffle(CloudList *this_cloud_list)
{
if (!settings.shuffle_words) { return; }
//we want to do add some randomness, but instead of basing it purely on size of words, lets base it
//on the actual area used
//first, lets get a sum of the total area used by all main words
int pre_shuffle_index = 0;
if (settings.shuffle_mark < 100)
{
//CloudList tmp = *this_cloud_list;
double total_area = 0;
for(itCloudList it = this_cloud_list->begin(); it != (this_cloud_list->begin()) + settings.maximum_words; it++)
{
total_area += (*it)->width() * (*it)->height();
}
//okay - we got total area.
//now, loop thru the list again, and find out where we hit both the pre_shuffle_amount mark an the mix amount mark
double pre_shuffle_mark = (total_area / (double)100) * settings.shuffle_mark;
double running_total = 0;
int count = 0;
for(itCloudList it = this_cloud_list->begin(); it < (this_cloud_list->begin() + settings.maximum_words); it++)
{
running_total += (*it)->width() * (*it)->height();
if (running_total > pre_shuffle_mark)
{
pre_shuffle_index = count;
break;
}
count++;
}
}
else {
pre_shuffle_index = this_cloud_list->size();
}
if (settings.verbose) { cout << "Shuffling the first " << pre_shuffle_index << " words. " << endl; }
random_shuffle(this_cloud_list->begin(), this_cloud_list->begin()+pre_shuffle_index);
// running_total = 0;
// int pre_shuffle_mix_index = 0;
// for(itCloudList it = this_cloud_list->begin(); it < (this_cloud_list->begin() + settings.maximum_words); it++)
// {
// running_total += (*it)->width() * (*it)->height();
// if (running_total > pre_shuffle_mix_mark)
// {
// pre_shuffle_mix_index = count;
// break;
// }
// count++;
// }
//
// if (settings.verbose) { cout << "PreMix: " << pre_shuffle_mix_index << endl;}
//
// random_shuffle(this_cloud_list->begin(), this_cloud_list->begin()+pre_shuffle_mix_index+1);
}