Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When redrawing the sample firstNameusingWordPreset, word placing don't avoid collision #47

Open
spapin opened this issue Oct 18, 2013 · 2 comments

Comments

@spapin
Copy link

spapin commented Oct 18, 2013

Using Processing 2 on mac os,

when clicking on the outputwindow, the wordcram is redrawn, however some names are placed on top of each other.

screen shot 2013-10-18 at 13 57 14

I assume this is related to the instanciation of WordCram:

wc = new WordCram(this);

I believe the "this" passed as argument keeps artifact values that disrupt the new wordcram.

@spapin
Copy link
Author

spapin commented Oct 24, 2013

Update on this issue: the problem is related to the fact that the Word array used for two subsequent WordCram is the same.

However, the class Word holds memory of some information related to the WordCram the word was involved in.

For instance, once a word is skipped for the first time, the attribute

Word.skippedBecause

is set to a value explaining why the word was skip.
Upon drawing a new WordCram, this skippedReason persists. The piece of code handling word collision will do the following:

        boolean foundOverlap = false;
        for (int i = 0; !foundOverlap && i < eWordIndex; i++) {
            EngineWord otherWord = eWords[i];
            if (otherWord.wasSkipped()) continue; //can't overlap with skipped word

            if (eWord.overlaps(otherWord)) {
                foundOverlap = true;
                lastCollidedWith = otherWord;
            }
        }

        if (!foundOverlap) {
            eWord.finalizeLocation();
            return true;
        }

Here, the otherword may have been skipped in a previous wordcram: collision detection will not apply.

The proposed fix is to delegate the skipped/not skipped property to the WordCram class.

@danbernier
Copy link
Owner

Yeah, you can't re-use a WordCram instance for another drawing - it's easier to just make a new one.

This does mean that you'll have to re-parse the text, but that's usually not too time-consuming, compared to the layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants