You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
4.1 KiB
168 lines
4.1 KiB
package shared.model;
|
|
|
|
|
|
import shared.enums.RoundingType;
|
|
|
|
/**
|
|
* Represents a compound mark - that is, either one or two individual marks which form a single compound mark.
|
|
*/
|
|
public class CompoundMark {
|
|
|
|
/**
|
|
* The ID of the compound mark.
|
|
*/
|
|
private int id;
|
|
|
|
/**
|
|
* The name of the compound mark.
|
|
*/
|
|
private String name;
|
|
|
|
/**
|
|
* The first mark in the compound mark.
|
|
*/
|
|
private Mark mark1;
|
|
|
|
/**
|
|
* The second mark in the compound mark.
|
|
*/
|
|
private Mark mark2;
|
|
|
|
/**
|
|
* The average coordinate of the compound mark.
|
|
*/
|
|
private GPSCoordinate averageGPSCoordinate;
|
|
|
|
/**
|
|
* The side that the mark must be rounded on
|
|
*/
|
|
private RoundingType roundingType;
|
|
|
|
|
|
/**
|
|
* Constructs a compound mark from a single mark.
|
|
* @param id the id of the compound mark
|
|
* @param name name of the compound mark
|
|
* @param mark1 The individual mark that comprises this compound mark.
|
|
*/
|
|
public CompoundMark(int id, String name, Mark mark1) {
|
|
this.id = id;
|
|
this.name = name;
|
|
this.mark1 = mark1;
|
|
this.averageGPSCoordinate = calculateAverage();
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Constructs a compound mark from a pair of marks.
|
|
* @param id the id of the compound mark
|
|
* @param name name of the compound mark
|
|
* @param mark1 The first individual mark that comprises this compound mark.
|
|
* @param mark2 The second individual mark that comprises this compound mark.
|
|
*/
|
|
public CompoundMark(int id, String name, Mark mark1, Mark mark2) {
|
|
this.id = id;
|
|
this.name = name;
|
|
this.mark1 = mark1;
|
|
this.mark2 = mark2;
|
|
this.averageGPSCoordinate = calculateAverage();
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Returns the ID of this compound mark.
|
|
* @return The ID of this compound mark.
|
|
*/
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
/**
|
|
* Returns the name of this compound mark
|
|
* @return The name of this compound mark.
|
|
*/
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
/**
|
|
* Returns the first mark of the compound mark.
|
|
* @return The first mark of the compound mark.
|
|
*/
|
|
public Mark getMark1() {
|
|
return mark1;
|
|
}
|
|
|
|
/**
|
|
* Returns the second mark of the compound mark.
|
|
* @return The second mark of the compound mark.
|
|
*/
|
|
public Mark getMark2() {
|
|
return mark2;
|
|
}
|
|
|
|
|
|
/**
|
|
* Returns the position of the first mark in the compound mark.
|
|
* @return The position of the first mark in the compound mark.
|
|
*/
|
|
public GPSCoordinate getMark1Position() {
|
|
return mark1.getPosition();
|
|
}
|
|
|
|
/**
|
|
* Returns the position of the second mark in the compound mark.
|
|
* @return The position of the second mark in the compound mark.
|
|
*/
|
|
public GPSCoordinate getMark2Position() {
|
|
return mark2.getPosition();
|
|
}
|
|
|
|
|
|
/**
|
|
* Returns the average coordinate of the compound mark.
|
|
* @return The average coordinate of the compound mark.
|
|
*/
|
|
public GPSCoordinate getAverageGPSCoordinate() {
|
|
return averageGPSCoordinate;
|
|
}
|
|
|
|
|
|
/**
|
|
* Calculates the average coordinate of the compound mark.
|
|
* @return The average coordinate of the compound mark.
|
|
*/
|
|
private GPSCoordinate calculateAverage() {
|
|
|
|
//If the compound mark only contains one mark, the average is simply the first mark's position.
|
|
if (this.mark2 == null) {
|
|
return this.getMark1Position();
|
|
}
|
|
|
|
|
|
//Otherwise, calculate the average of both marks.
|
|
GPSCoordinate averageCoordinate = GPSCoordinate.calculateAverageCoordinate(this.getMark1Position(), this.getMark2Position());
|
|
|
|
return averageCoordinate;
|
|
|
|
}
|
|
|
|
/**
|
|
* Used to get how this mark should be rounded
|
|
* @return rounding type for mark
|
|
*/
|
|
public RoundingType getRoundingType() {
|
|
return roundingType;
|
|
}
|
|
|
|
/**
|
|
* Used to set the type of rounding for this mark
|
|
* @param roundingType rounding type to set
|
|
*/
|
|
public void setRoundingType(RoundingType roundingType) {
|
|
this.roundingType = roundingType;
|
|
}
|
|
}
|