<commit_before>package worldgui;

import utils.Vector;
import air.Aircraft;
import air.SimWorld;

public class AircraftPosition  {

	private air.Aircraft aircraft;
	
	public AircraftPosition() {	}

	public void setAircraft(Aircraft a){
		this.aircraft = a;
	}
	
	protected Vector getPosition() {
		int state = this.aircraft.getState();
		
		switch (state) {
			case air.Aircraft.ON_FLIGHT:
				return this.getFlightPosition();
			case air.Aircraft.ON_GROUND:
			case air.Aircraft.WAITING_FOR_TAKE_OFF:
				return this.getGroundPosition();
			case air.Aircraft.TAKING_OFF:
				Vector position = this.getTakeoffPosition();
				//System.err.println(position);
				return position;
			case air.Aircraft.ON_HOLDING_LOOP:
				return this.getHoldingLoopPosition();
			case air.Aircraft.LANDING:
			case air.Aircraft.ARRIVING: 
				return this.getLandingPosition();
		}
		
		return this.getGroundPosition();
	}
	
	private Vector getGroundPosition() {
		double xPos = this.aircraft.getCurrentAirPort().getX1();
		double yPos = this.aircraft.getCurrentAirPort().getY1();
		
		return new Vector(new double[] {xPos, yPos});
	}
	
	private Vector getTakeoffPosition() {
		
		double xPos = this.aircraft.getCurrentAirPort().getX1();
		double yPos = this.aircraft.getCurrentAirPort().getY1();
		
		long t0        = this.aircraft.getLastTime();
		long t         = SimWorld.getInstance().getSimulator().getClock().getCurrentSimulationTime();
		
		double runwayLength = this.aircraft.getCurrentAirPort().getRunwayLength();
		double maxSpeed     = this.aircraft.getMaxSpeed();
		double breakAcc     = Math.pow(maxSpeed, 2) / (2 * runwayLength);
		
		Vector runwayBegin = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX1(),
						this.aircraft.getCurrentAirPort().getY1()
						}
				);
		
		Vector runwayEnd = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX2(),
						this.aircraft.getCurrentAirPort().getY2()
						}
				);
		
		Vector runway = runwayEnd.sub(runwayBegin);
		runway = runway.normalize();
		Vector head = runway.multiply((t - t0) * maxSpeed);
		Vector tail = runway.multiply(0.5 * Math.pow((t - t0), 2) * -breakAcc);
		//System.out.println("V_max: " + maxSpeed + ", break_acc: " + breakAcc);
		//System.out.println("head: " + head + ", tail: "+tail);
		
		return new Vector(new double[] {
				xPos + head.getX() - tail.getX(),
				yPos + head.getY() - tail.getY() 
		});
			
	}
	
	private double getAcceleration() {
		return this.aircraft.getMaxAcceleration();
	}
	
	private double getSpeed() {
		return this.aircraft.getMaxSpeed();
	}

	private Vector getFlightPosition() {
		double lastX   = this.aircraft.getLastX();
		double lastY   = this.aircraft.getLastY();
		
		long t0        = this.aircraft.getLastTime();
		long t         = SimWorld.getInstance().getSimulator().getClock().getCurrentSimulationTime();
		double speed   = this.getSpeed();
		double targetX = this.aircraft.getDestination().getX2();
		double targetY = this.aircraft.getDestination().getY2();
		
		Vector n       = new Vector(new double[] {targetX - lastX, targetY - lastY});
		n = n.normalize();
	
		Vector tail = n.multiply((t - t0) * (speed));
		return new Vector(new double[] {
				lastX + tail.getComponent(0),
				lastY + tail.getComponent(1)
		});
	}
	
	private Vector getHoldingLoopPosition() {
		
		// end of the runway of destination airport
		double lastX   = this.aircraft.getLastX();
		double lastY   = this.aircraft.getLastY();
		
		long t0        = this.aircraft.getLastTime();
		long t         = SimWorld.getInstance().getSimulator().getClock().getCurrentSimulationTime();
				
		Vector runwayBegin = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX1(),
						this.aircraft.getCurrentAirPort().getY1()
						}
				);
		
		Vector runwayEnd = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX2(),
						this.aircraft.getCurrentAirPort().getY2()
						}
				);
		
		Vector runway = runwayEnd.sub(runwayBegin);
		Vector runwayRotated = runway.rotate(Math.PI /  2);
		
		// angular velocity
		double w = 0.02;

		Vector n = runwayBegin.add(runway.multiply(Math.cos((t - t0) * w)));
		n = n.add(runwayRotated.multiply(Math.sin((t - t0) * w)));	
		return n;
	}
	
	private Vector getLandingPosition(){
		double xPos = this.aircraft.getCurrentAirPort().getX2();
		double yPos = this.aircraft.getCurrentAirPort().getY2();
		
		long t0        = this.aircraft.getLastTime();
		long t         = SimWorld.getInstance().getSimulator().getClock().getCurrentSimulationTime();
		
		double runwayLength = this.aircraft.getCurrentAirPort().getRunwayLength();
		double maxSpeed     = this.aircraft.getMaxSpeed();
		double breakAcc     = Math.pow(maxSpeed, 2) / (2 * runwayLength);
		
		Vector runwayBegin = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX2(),
						this.aircraft.getCurrentAirPort().getY2()
						}
				);
		
		Vector runwayEnd = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX1(),
						this.aircraft.getCurrentAirPort().getY1()
						}
				);
		
		Vector runway = runwayEnd.sub(runwayBegin);
		runway = runway.normalize();
		Vector head = runway.multiply((t - t0) * maxSpeed);
		Vector tail = runway.multiply(0.5 * Math.pow((t - t0), 2) * breakAcc);
		//System.out.println("V_max: " + maxSpeed + ", break_acc: " + breakAcc);
		//System.out.println("head: " + head + ", tail: "+tail);
		
		return new Vector(new double[] {
				xPos + head.getX() - tail.getX(),
				yPos + head.getY() - tail.getY() 
		});
	}
	
	
}
<commit_msg>implemented start position calculation<commit_after>package worldgui;

import utils.AirportLogger;
import utils.Vector;
import air.Aircraft;
import air.Event;
import air.SimWorld;

public class AircraftPosition  {

	private air.Aircraft aircraft;
	
	public AircraftPosition() {	}

	public void setAircraft(Aircraft a){
		this.aircraft = a;
	}
	
	protected Vector getPosition() {
		int state = this.aircraft.getState();
		
		switch (state) {
			case air.Aircraft.ON_FLIGHT:
				return this.getFlightPosition();
			case air.Aircraft.ON_GROUND:
			case air.Aircraft.WAITING_FOR_TAKE_OFF:
				return this.getGroundPosition();
			case air.Aircraft.TAKING_OFF:
				Vector position = this.getTakeoffPosition();
				//System.err.println(position);
				return position;
			case air.Aircraft.ON_HOLDING_LOOP:
				return this.getHoldingLoopPosition();
			case air.Aircraft.LANDING:
			case air.Aircraft.ARRIVING: 
				return this.getLandingPosition();
		}
		
		return this.getGroundPosition();
	}
	
	private Vector getGroundPosition() {
		double xPos = this.aircraft.getCurrentAirPort().getX1();
		double yPos = this.aircraft.getCurrentAirPort().getY1();
		
		return new Vector(new double[] {xPos, yPos});
	}
	
	private Vector getTakeoffPosition() {
		
		double xPos = this.aircraft.getCurrentAirPort().getX1();
		double yPos = this.aircraft.getCurrentAirPort().getY1();
		
		long startTime 			= this.aircraft.getLastTime();
		long currentTime		= SimWorld.getInstance().getSimulator().getClock().getCurrentSimulationTime();
		long timeOnRunway 		= currentTime - startTime;
		
		double runwayLength 	= this.aircraft.getCurrentAirPort().getRunwayLength();
		double maxSpeed     	= this.aircraft.getMaxSpeed();
		double startAcc     	= this.aircraft.getMaxAcceleration();
		double accTime			= maxSpeed / startAcc;
		double accDistance		= startAcc * accTime * accTime/2.0;
		double constDistance	= runwayLength - accDistance;
		double constTime		= constDistance / maxSpeed;
		double takeoffTime		= accTime + constTime;
		double distanceOnRunway	= 0;
		
		/*AirportLogger.getLogger().debug(
				"TAKEOFF runwayLenght: " + runwayLength + 
				", accDistance: " + accDistance + 
				", constDistance: " + constDistance + 
				", accelerationTime: " + accTime +
				", constantTime: " + constTime +
				", takeoffTime: " + takeoffTime 
				);*/
		
		if(timeOnRunway <= accTime){
			// aircraft is still accelerating
			distanceOnRunway = Math.pow(timeOnRunway, 2) / 2 * startAcc;
		} else {
			// aircraft is on full speed
			distanceOnRunway = accDistance + (timeOnRunway - accTime) * maxSpeed;			
		}
		
		// calculate position
		Vector runwayBegin = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX1(),
						this.aircraft.getCurrentAirPort().getY1()
						}
				);
		
		Vector runwayEnd = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX2(),
						this.aircraft.getCurrentAirPort().getY2()
						}
				);
		
		Vector runway = runwayEnd.sub(runwayBegin);
		runway = runway.normalize();
		Vector aircraftOnRunway = runway.multiply(distanceOnRunway);

		return new Vector(new double[] {
				xPos + aircraftOnRunway.getX(),
				yPos + aircraftOnRunway.getY()
		});
			
	}
	
	private double getAcceleration() {
		return this.aircraft.getMaxAcceleration();
	}
	
	private double getSpeed() {
		return this.aircraft.getMaxSpeed();
	}

	private Vector getFlightPosition() {
		double lastX   = this.aircraft.getLastX();
		double lastY   = this.aircraft.getLastY();
		
		long t0        = this.aircraft.getLastTime();
		long t         = SimWorld.getInstance().getSimulator().getClock().getCurrentSimulationTime();
		double speed   = this.getSpeed();
		double targetX = this.aircraft.getDestination().getX2();
		double targetY = this.aircraft.getDestination().getY2();
		
		Vector n       = new Vector(new double[] {targetX - lastX, targetY - lastY});
		n = n.normalize();
	
		Vector tail = n.multiply((t - t0) * (speed));
		return new Vector(new double[] {
				lastX + tail.getComponent(0),
				lastY + tail.getComponent(1)
		});
	}
	
	private Vector getHoldingLoopPosition() {
		
		// end of the runway of destination airport
		double lastX   = this.aircraft.getLastX();
		double lastY   = this.aircraft.getLastY();
		
		long t0        = this.aircraft.getLastTime();
		long t         = SimWorld.getInstance().getSimulator().getClock().getCurrentSimulationTime();
				
		Vector runwayBegin = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX1(),
						this.aircraft.getCurrentAirPort().getY1()
						}
				);
		
		Vector runwayEnd = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX2(),
						this.aircraft.getCurrentAirPort().getY2()
						}
				);
		
		Vector runway = runwayEnd.sub(runwayBegin);
		Vector runwayRotated = runway.rotate(Math.PI /  2);
		
		// angular velocity
		double w = 0.02;

		Vector n = runwayBegin.add(runway.multiply(Math.cos((t - t0) * w)));
		n = n.add(runwayRotated.multiply(Math.sin((t - t0) * w)));	
		return n;
	}
	
	private Vector getLandingPosition(){
		double xPos = this.aircraft.getCurrentAirPort().getX2();
		double yPos = this.aircraft.getCurrentAirPort().getY2();
		
		long t0        = this.aircraft.getLastTime();
		long t         = SimWorld.getInstance().getSimulator().getClock().getCurrentSimulationTime();
		
		double runwayLength = this.aircraft.getCurrentAirPort().getRunwayLength();
		double maxSpeed     = this.aircraft.getMaxSpeed();
		double breakAcc     = Math.pow(maxSpeed, 2) / (2 * runwayLength);
		
		Vector runwayBegin = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX2(),
						this.aircraft.getCurrentAirPort().getY2()
						}
				);
		
		Vector runwayEnd = new Vector(
				new double[] {
						this.aircraft.getCurrentAirPort().getX1(),
						this.aircraft.getCurrentAirPort().getY1()
						}
				);
		
		Vector runway = runwayEnd.sub(runwayBegin);
		runway = runway.normalize();
		Vector head = runway.multiply((t - t0) * maxSpeed);
		Vector tail = runway.multiply(0.5 * Math.pow((t - t0), 2) * breakAcc);
		//System.out.println("V_max: " + maxSpeed + ", break_acc: " + breakAcc);
		//System.out.println("head: " + head + ", tail: "+tail);
		
		return new Vector(new double[] {
				xPos + head.getX() - tail.getX(),
				yPos + head.getY() - tail.getY() 
		});
	}
	
	
}

{'fraction_non_alphanumeric': 0.13493996137375094, 'fraction_numerical': 0.007641279704425225, 'mean_word_length': 3.3043006866642575, 'pattern_counts': {'":': 0, '<': 4, '<?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': '2354957', 'n_tokens_mistral': 4602, 'n_tokens_neox': 3825, 'n_words': 751}