<commit_before>package graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import structures.Level;
import structures.Point2d;

/**
 * Holder class for the trail drawing effect
 * @author <NAME>
 */
public final class TrailEffect extends GraphicEffect {

	private static ArrayList<Point2d> trailPoints = new ArrayList<Point2d>();

	/**
	 * Adds a point the to current trail.
	 * @param point a parameter
	 */
	public static void addTrailPoint(Point2d point) {
		trailPoints.add(point);
	}

	/**
	 * Clears all points from the saved trail.
	 */
	public static void resetPoints() {
		trailPoints.clear();
	}

	/**
	 * Draws the trail effect.
	 * @param trailPoints the list of points in the trail
	 * @param level the current Level
	 * @param g the Graphics component to draw with
	 */
	public static void draw(Level level, Graphics g) {
		try {
			double screenXShift = level.getScreenXShift();
			double screenYShift = level.getScreenYShift();
			Color c = Color.green;
			g.setColor(c);
			for (int i = 0; i < trailPoints.size() - 2; i++) {
				if (trailPoints.get(i) != null
						&& trailPoints.get(i + 1) != null) {
					g.drawLine(
							(int) (Math.round(trailPoints.get(i).x
									+ screenXShift)),
							(int) (Math.round(trailPoints.get(i).y
									+ screenYShift)),
							(int) (Math.round(trailPoints.get(i + 1).x
									+ screenXShift)),
							(int) (Math.round(trailPoints.get(i + 1).y
									+ screenYShift)));

				}
			}
		} catch (Exception e) {

		}

	}

}<commit_msg>Refactored to simplify graphics.TrailEffect code<commit_after>package graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

import structures.Level;
import structures.Point2d;

/**
 * Holder class for the trail drawing effect
 * @author <NAME>
 */
public final class TrailEffect extends GraphicEffect {

	private static ArrayList<Point2d> trailPoints = new ArrayList<Point2d>(100);

	/**
	 * Adds a point the to current trail.
	 * @param point a parameter
	 */
	public static void addTrailPoint(Point2d point) {
		trailPoints.add(point);
	}

	/**
	 * Clears all points from the saved trail.
	 */
	public static void resetPoints() {
		trailPoints.clear();
	}

	/**
	 * Draws the trail effect.
	 * @param trailPoints the list of points in the trail
	 * @param level the current Level
	 * @param g the Graphics component to draw with
	 */
	public static void draw(Level level, Graphics g) {
		double screenXShift = level.getScreenXShift();
		double screenYShift = level.getScreenYShift();
		
		// number of points to draw
		int n = trailPoints.size() - 2;
		g.setColor(Color.green);		
		
		for (int i = 0; i < n; i++) {
			Point2d from = trailPoints.get(i);
			Point2d to   = trailPoints.get(i + 1);
			int fromX = round(from.x + screenXShift);
			int fromY = round(from.y + screenYShift);
			int toX   = round(to.x   + screenXShift);
			int toY   = round(to.y   + screenYShift);
			g.drawLine(fromX, fromY, toX, toY);
		}
	}
	
	// convenience method since Math.round returns a long
	private static int round(double x) {
		return (int) Math.round(x);
	}

}
{'fraction_non_alphanumeric': 0.11975664425232149, 'fraction_numerical': 0.0067243035542747355, 'mean_word_length': 3.210242587601078, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '5805771', 'n_tokens_mistral': 1164, 'n_tokens_neox': 993, 'n_words': 302}