1 package net.sf.openrocket.simulation;
3 import net.sf.openrocket.util.Coordinate;
4 import net.sf.openrocket.util.MathUtil;
7 * An immutable value object containing the mass data of a rocket.
9 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
11 public class MassData {
13 private final Coordinate cg;
14 private final double longitudinalInertia;
15 private final double rotationalInertia;
18 public MassData(Coordinate cg, double longitudinalInertia, double rotationalInertia) {
20 throw new IllegalArgumentException("cg is null");
23 this.longitudinalInertia = longitudinalInertia;
24 this.rotationalInertia = rotationalInertia;
30 public Coordinate getCG() {
34 public double getLongitudinalInertia() {
35 return longitudinalInertia;
38 public double getRotationalInertia() {
39 return rotationalInertia;
45 public boolean equals(Object obj) {
48 if (!(obj instanceof MassData))
51 MassData other = (MassData) obj;
52 return (this.cg.equals(other.cg) && MathUtil.equals(this.longitudinalInertia, other.longitudinalInertia) &&
53 MathUtil.equals(this.rotationalInertia, other.rotationalInertia));
58 public int hashCode() {
59 return (int) (cg.hashCode() ^ Double.doubleToLongBits(longitudinalInertia) ^ Double.doubleToLongBits(rotationalInertia));
64 public String toString() {
65 return "MassData [cg=" + cg + ", longitudinalInertia=" + longitudinalInertia
66 + ", rotationalInertia=" + rotationalInertia + "]";