<commit_before>package org.lsfn.console_pc;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

import org.lsfn.console_pc.STS.STSdown;
import org.lsfn.console_pc.STS.STSup;
import org.lsfn.console_pc.SpaceObject.ObjectType;

public class PilotingPanel extends JPanel implements MouseListener, KeyListener {
    
    // TODO zoom
    private static int scale = 10;
    
    private PilotingDisplay pilotingDisplay;
    private List<SpaceObject> objectList;
    private boolean[] keyStates, keyStatesChanged;
    
    public PilotingPanel(PilotingDisplay pilotingDisplay) {
        this.pilotingDisplay = pilotingDisplay;
        this.objectList = new ArrayList<SpaceObject>();
        
        /* Key state array indices correspondence chart:
            0: Turn Anti-clockwise
            1: Turn Clockwise
            2: Strafe Left
            3: Strafe Right
            4: Forward Thrust
            5: Backwards Thrust
        */
        this.keyStates = new boolean[6];
        for(int i = 0; i < this.keyStates.length; i++) {
            this.keyStates[i] = false;
        }
        this.keyStatesChanged = new boolean[6];
        for(int i = 0; i < this.keyStatesChanged.length; i++) {
            this.keyStatesChanged[i] = false;
        }
        
        this.addMouseListener(this);
    }
    
    private void paintCalibration(Graphics g) {
        int squareSize = 10;
        Rectangle bounds = this.getBounds();
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, squareSize, squareSize);
        g.fillRect(bounds.width - squareSize - 1, 0, squareSize, squareSize);
        g.fillRect(0, bounds.height - squareSize - 1, squareSize, squareSize);
        g.fillRect(bounds.width - squareSize - 1, bounds.height - squareSize - 1, squareSize, squareSize);
        g.setColor(Color.RED);
        g.drawRect(0, 0, squareSize, squareSize);
        g.drawRect(bounds.width - squareSize - 1, 0, squareSize, squareSize);
        g.drawRect(0, bounds.height - squareSize - 1, squareSize, squareSize);
        g.drawRect(bounds.width - squareSize - 1, bounds.height - squareSize - 1, squareSize, squareSize);
    }
    
    private void paintBackground(Graphics2D g2d) {
        int width = this.getBounds().width;
        int height = this.getBounds().height;
        if(width > height) {
            g2d.fillOval(width/2 - height/2, 0, height, height);
        } else {
            g2d.fillOval(0, height/2 - width/2, width, width);
        }        
    }
    
    private void paintObjects(Graphics2D g2d) {
        int centreX = this.getBounds().width / 2;
        int centreY = this.getBounds().height / 2;
        for(SpaceObject so : this.objectList) {
            if(so.getObjectType() == ObjectType.SHIP) {
                int[] xs = new int[3];
                int[] ys = new int[3];
                xs[0] = ((int)((Math.cos(so.getTheta()) * 2) + so.getX()) * scale) + centreX;
                ys[0] = -((int)((Math.sin(so.getTheta()) * 2) + so.getY()) * scale) + centreY;
                xs[1] = ((int)((Math.cos(so.getTheta() + (Math.PI/2))) + so.getX()) * scale) + centreX;
                ys[1] = -((int)((Math.sin(so.getTheta() + (Math.PI/2))) + so.getY()) * scale) + centreY;
                xs[2] = ((int)((Math.cos(so.getTheta() - (Math.PI/2))) + so.getX()) * scale) + centreX;
                ys[2] = -((int)((Math.sin(so.getTheta() - (Math.PI/2))) + so.getY()) * scale) + centreY;
                g2d.setColor(Color.GREEN);
                g2d.fillPolygon(xs, ys, 3);
            } else if(so.getObjectType() == ObjectType.ASTEROID) {
                g2d.setColor(Color.YELLOW);
                g2d.fillOval((int)this.convertX(so.getX()) - scale, (int)this.convertY(so.getY()) - scale, scale*2, scale*2);
            }
        }
    }
    
    private void paintOwnShip(Graphics2D g2d) {
        int centreX = this.getBounds().width / 2;
        int centreY = this.getBounds().height / 2;
        int[] xs = new int[3];
        int[] ys = new int[3];
        xs[0] = centreX;
        ys[0] = -(2 * scale) + centreY;
        xs[1] = -scale + centreX;
        ys[1] = centreY;
        xs[2] = scale + centreX;
        ys[2] = centreY;
        g2d.setColor(Color.GREEN);
        g2d.fillPolygon(xs, ys, 3);
    }
    
    private void paintElements(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        paintBackground(g2d);
        paintObjects(g2d);
        paintOwnShip(g2d);
    }
    
    private void clearPanel(Graphics g) {<commit_msg>Fixes for drawing other ships more correctly.<commit_after>package org.lsfn.console_pc;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

import org.lsfn.console_pc.STS.STSdown;
import org.lsfn.console_pc.STS.STSup;
import org.lsfn.console_pc.SpaceObject.ObjectType;

public class PilotingPanel extends JPanel implements MouseListener, KeyListener {
    
    // TODO zoom
    private static int scale = 10;
    
    private PilotingDisplay pilotingDisplay;
    private List<SpaceObject> objectList;
    private boolean[] keyStates, keyStatesChanged;
    
    public PilotingPanel(PilotingDisplay pilotingDisplay) {
        this.pilotingDisplay = pilotingDisplay;
        this.objectList = new ArrayList<SpaceObject>();
        
        /* Key state array indices correspondence chart:
            0: Turn Anti-clockwise
            1: Turn Clockwise
            2: Strafe Left
            3: Strafe Right
            4: Forward Thrust
            5: Backwards Thrust
        */
        this.keyStates = new boolean[6];
        for(int i = 0; i < this.keyStates.length; i++) {
            this.keyStates[i] = false;
        }
        this.keyStatesChanged = new boolean[6];
        for(int i = 0; i < this.keyStatesChanged.length; i++) {
            this.keyStatesChanged[i] = false;
        }
        
        this.addMouseListener(this);
    }
    
    private void paintCalibration(Graphics g) {
        int squareSize = 10;
        Rectangle bounds = this.getBounds();
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, squareSize, squareSize);
        g.fillRect(bounds.width - squareSize - 1, 0, squareSize, squareSize);
        g.fillRect(0, bounds.height - squareSize - 1, squareSize, squareSize);
        g.fillRect(bounds.width - squareSize - 1, bounds.height - squareSize - 1, squareSize, squareSize);
        g.setColor(Color.RED);
        g.drawRect(0, 0, squareSize, squareSize);
        g.drawRect(bounds.width - squareSize - 1, 0, squareSize, squareSize);
        g.drawRect(0, bounds.height - squareSize - 1, squareSize, squareSize);
        g.drawRect(bounds.width - squareSize - 1, bounds.height - squareSize - 1, squareSize, squareSize);
    }
    
    private void paintBackground(Graphics2D g2d) {
        int width = this.getBounds().width;
        int height = this.getBounds().height;
        g2d.setColor(new Color(0, 0, 128));
        if(width > height) {
            g2d.fillOval(width/2 - height/2, 0, height, height);
        } else {
            g2d.fillOval(0, height/2 - width/2, width, width);
        }        
    }
    
    private void paintObjects(Graphics2D g2d) {
        for(SpaceObject so : this.objectList) {
            if(so.getObjectType() == ObjectType.SHIP) {
                int[] xs = new int[3];
                int[] ys = new int[3];
                xs[0] = (int)(convertX((-Math.sin(so.getTheta()) * 2) + so.getX()));
                ys[0] = (int)(convertY((Math.cos(so.getTheta()) * 2) + so.getY()));
                xs[1] = (int)(convertX(Math.cos(so.getTheta()) + so.getX()));
                ys[1] = (int)(convertY(Math.sin(so.getTheta()) + so.getY()));
                xs[2] = (int)(convertX(-Math.cos(so.getTheta()) + so.getX()));
                ys[2] = (int)(convertY(-Math.sin(so.getTheta()) + so.getY()));
                g2d.setColor(Color.GREEN);
                g2d.fillPolygon(xs, ys, 3);
            } else if(so.getObjectType() == ObjectType.ASTEROID) {
                g2d.setColor(Color.YELLOW);
                g2d.fillOval((int)convertX(so.getX()) - scale, (int)convertY(so.getY()) - scale, scale*2, scale*2);
            }
        }
    }
    
    private void paintOwnShip(Graphics2D g2d) {
        int centreX = this.getBounds().width / 2;
        int centreY = this.getBounds().height / 2;
        int[] xs = new int[3];
        int[] ys = new int[3];
        xs[0] = centreX;
        ys[0] = -(2 * scale) + centreY;
        xs[1] = -scale + centreX;
        ys[1] = centreY;
        xs[2] = scale + centreX;
        ys[2] = centreY;
        g2d.setColor(Color.GREEN);
        g2d.fillPolygon(xs, ys, 3);
    }
    
    private void paintElements(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        paintBackground(g2d);
        paintObjects(g2d);
        paintOwnShip(g2d);
    }
    
    private void clearPanel(Graphics g) {
{'fraction_non_alphanumeric': 0.13410613633946614, 'fraction_numerical': 0.018717430607253005, 'mean_word_length': 2.1997277985709425, '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': '5925616', 'n_tokens_mistral': 3132, 'n_tokens_neox': 3025, 'n_words': 636}