WordCram icon indicating copy to clipboard operation
WordCram copied to clipboard

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

Open spapin opened this issue 11 years ago • 2 comments

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 avatar Oct 18 '13 12:10 spapin

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.

spapin avatar Oct 24 '13 11:10 spapin

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.

danbernier avatar Oct 25 '13 14:10 danbernier