<commit_before>package org.jtrfp.trcl.core;

import org.jtrfp.trcl.Controller;
import org.jtrfp.trcl.Tickable;
import org.jtrfp.trcl.IntTransferFunction;

public class WindowAnimator implements Tickable {
    private final TriangleVertex2FlatDoubleWindow w;
    private final int numElements, numFrames;
    private final float[][] frames;
    private final boolean loopInterpolate;
    private final Controller controller;
    private int indexCounter=0;
    private final IntTransferFunction indexXferFun;
    private String debugName;
    public WindowAnimator(TriangleVertex2FlatDoubleWindow w, 
	    int numElements, int numFrames,
	    boolean loopInterpolate, Controller controller, IntTransferFunction indexXferFun){
	if(controller==null) throw new NullPointerException("Controller is intolerably null.");
	if(w==null) throw new NullPointerException("TriangleVertex2FlatDoubleWindow is intolerably null.");
	this.w=w;
	this.numElements=numElements;
	this.numFrames=numFrames;
	this.indexXferFun=indexXferFun;
	//this.startElement=startElement;
	frames = new float[numElements*numFrames][];
	this.loopInterpolate=loopInterpolate;
	this.controller=controller;
    }
    public void addFrames(float[] newFrames) {
	//indices[indexCounter]=globalFlatID;
	frames[indexCounter]=(newFrames);
	indexCounter++;
    }//end constructor
    
    @Override
    public void tick(){
	if(indexCounter<numElements){
	    return;}
	final double frame=controller.getCurrentFrame();
	//controller.unstale();
	int lowFrame = (int)frame;
	int hiFrame = (lowFrame+1)%numFrames;
	double interpolation = frame-(double)lowFrame;
	if(hiFrame==0 && !loopInterpolate){lowFrame=0;hiFrame=1;}
	double hI=interpolation;
	double lI=1.-interpolation;
	for(int index=0; index<numElements; index++){
	    final double val = frames[index][lowFrame]*lI+frames[index][hiFrame]*hI;
	    //System.out.println("Element index="+index+" location="+indexXferFun.transfer(index));
	    //if(debugName!=null)if(debugName.contains("uvAnimator"))System.out.println("name: "+debugName+": "+indexXferFun.transfer(index)+" set to "+val);
	    w.set(
		    indexXferFun.transfer(index), val);<commit_msg>Optimization: Switched to 1D array in WindowAnimator.<commit_after>package org.jtrfp.trcl.core;

import org.jtrfp.trcl.Controller;
import org.jtrfp.trcl.Tickable;
import org.jtrfp.trcl.IntTransferFunction;

public class WindowAnimator implements Tickable {
    private final TriangleVertex2FlatDoubleWindow w;
    private final int numElements, numFrames;
   // private final float[][] frames;
    private final float [] frames;
    private final boolean loopInterpolate;
    private final Controller controller;
    private int indexCounter=0;
    private final IntTransferFunction indexXferFun;
    private String debugName;
    public WindowAnimator(TriangleVertex2FlatDoubleWindow w, 
	    int numElements, int numFrames,
	    boolean loopInterpolate, Controller controller, IntTransferFunction indexXferFun){
	if(controller==null) throw new NullPointerException("Controller is intolerably null.");
	if(w==null) throw new NullPointerException("TriangleVertex2FlatDoubleWindow is intolerably null.");
	this.w=w;
	this.numElements=numElements;
	this.numFrames=numFrames;
	this.indexXferFun=indexXferFun;
	//this.startElement=startElement;
	frames = new float[numElements*numFrames];
	this.loopInterpolate=loopInterpolate;
	this.controller=controller;
    }
    public void addFrames(float[] newFrames) {
	//indices[indexCounter]=globalFlatID;
	System.arraycopy(newFrames, 0, frames, indexCounter*numFrames, numFrames);
	//frames[indexCounter]=(newFrames);
	indexCounter++;
    }//end constructor
    
    @Override
    public void tick(){
	if(indexCounter<numElements){
	    return;}
	final double frame=controller.getCurrentFrame();
	//controller.unstale();
	int lowFrame = (int)frame;
	int hiFrame = (lowFrame+1)%numFrames;
	double interpolation = frame-(double)lowFrame;
	if(hiFrame==0 && !loopInterpolate){lowFrame=0;hiFrame=1;}
	double hI=interpolation;
	double lI=1.-interpolation;
	final int dHi=hiFrame-lowFrame;
	int indexOffset=lowFrame;
	for(int index=0; index<numElements; index++){
	    //final double val = frames[index][lowFrame]*lI+frames[index][hiFrame]*hI;
	    final double val = frames[indexOffset]*lI+frames[indexOffset+dHi]*hI;
	    //System.out.println("Element index="+index+" location="+indexXferFun.transfer(index));
	    //if(debugName!=null)if(debugName.contains("uvAnimator"))System.out.println("name: "+debugName+": "+indexXferFun.transfer(index)+" set to "+val);
	    w.set(indexXferFun.transfer(index), val);
	    indexOffset+=numFrames;
{'fraction_non_alphanumeric': 0.11749460043196544, 'fraction_numerical': 0.004751619870410367, 'mean_word_length': 5.780380673499268, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5007724', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1414, 'n_words': 293}