<commit_before>package wordcram;

/*
Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;

import processing.core.*;

class WordCramEngine {

	private PGraphics destination;
	
	private WordFonter fonter;
	private WordSizer sizer;
	private WordColorer colorer;
	private WordAngler angler;
	private WordPlacer placer;
	private WordNudger nudger;
	
	private Word[] words; // just a safe copy
	private EngineWord[] eWords;
	private int eWordIndex = -1;
	
	private RenderOptions renderOptions;
	
	WordCramEngine(PGraphics destination, Word[] words, WordFonter fonter, WordSizer sizer, WordColorer colorer, WordAngler angler, WordPlacer placer, WordNudger nudger, WordShaper shaper, BBTreeBuilder bbTreeBuilder, RenderOptions renderOptions) {
		
		if (destination.getClass().equals(PGraphics2D.class)) {
			throw new Error("WordCram can't work with P2D buffers, sorry - try using JAVA2D.");
		}
		
		this.destination = destination;
		
		this.fonter = fonter;
		this.sizer = sizer;
		this.colorer = colorer;
		this.angler = angler;
		this.placer = placer;
		this.nudger = nudger;
		
		this.renderOptions = renderOptions;
		this.words = words;
		this.eWords = wordsIntoEngineWords(words, shaper, bbTreeBuilder);
	}
	
	private EngineWord[] wordsIntoEngineWords(Word[] words, WordShaper wordShaper, BBTreeBuilder bbTreeBuilder) {
		ArrayList<EngineWord> engineWords = new ArrayList<EngineWord>();
		
		int maxNumberOfWords = renderOptions.maxNumberOfWordsToDraw >= 0 ?
								renderOptions.maxNumberOfWordsToDraw :
								words.length;
		for (int i = 0; i < maxNumberOfWords; i++) {
			
			Word word = words[i];<commit_msg>Bug Fix #1: don't let maxNumberOfWords let you go past actual # of words<commit_after>package wordcram;

/*
Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;

import processing.core.*;

class WordCramEngine {

	private PGraphics destination;
	
	private WordFonter fonter;
	private WordSizer sizer;
	private WordColorer colorer;
	private WordAngler angler;
	private WordPlacer placer;
	private WordNudger nudger;
	
	private Word[] words; // just a safe copy
	private EngineWord[] eWords;
	private int eWordIndex = -1;
	
	private RenderOptions renderOptions;
	
	WordCramEngine(PGraphics destination, Word[] words, WordFonter fonter, WordSizer sizer, WordColorer colorer, WordAngler angler, WordPlacer placer, WordNudger nudger, WordShaper shaper, BBTreeBuilder bbTreeBuilder, RenderOptions renderOptions) {
		
		if (destination.getClass().equals(PGraphics2D.class)) {
			throw new Error("WordCram can't work with P2D buffers, sorry - try using JAVA2D.");
		}
		
		this.destination = destination;
		
		this.fonter = fonter;
		this.sizer = sizer;
		this.colorer = colorer;
		this.angler = angler;
		this.placer = placer;
		this.nudger = nudger;
		
		this.renderOptions = renderOptions;
		this.words = words;
		this.eWords = wordsIntoEngineWords(words, shaper, bbTreeBuilder);
	}
	
	private EngineWord[] wordsIntoEngineWords(Word[] words, WordShaper wordShaper, BBTreeBuilder bbTreeBuilder) {
		ArrayList<EngineWord> engineWords = new ArrayList<EngineWord>();
		
		int maxNumberOfWords = words.length;
		if (renderOptions.maxNumberOfWordsToDraw >= 0) {
			maxNumberOfWords = Math.min(maxNumberOfWords, renderOptions.maxNumberOfWordsToDraw);
		}

		for (int i = 0; i < maxNumberOfWords; i++) {
			Word word = words[i];
{'fraction_non_alphanumeric': 0.08267370272647317, 'fraction_numerical': 0.006816182937554969, 'mean_word_length': 4.665006226650062, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3607204', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1348, 'n_words': 452}