Android Open Source - dice-probabilities Vector






From Project

Back to project page dice-probabilities.

License

The source code is released under:

MIT License

If you think the Android project dice-probabilities listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.kleemann.diceprobabilities.graph;
/*from  w ww  .j av  a  2 s .c o  m*/
/**
 * <p>A vector (direction and magnitude) represented by a 
 * Point object. 
 */
class Vector {

  private final Point pt;
  
  /**
   * Creates a vector from the origin to the specified point
   * @param pt
   */
  public Vector(Point pt) {
    this.pt = pt;
  }
  
  /**
   * Returns the vector that points from the src to the dst point
   * @param src
   * @param dst
   */
  public Vector(Point src, Point dst) {
    this.pt = dst.sub(src);
  }

  public float magnitude() {
    final double w2 = (double)pt.getX()*pt.getX();
    final double h2 = (double)pt.getY()*pt.getY();
    // sqrt only takes double
    return (float)Math.sqrt(w2+h2);
  }
  
  public Vector scale(float f) {
    // scaling both axes scales the diagonal in the same proportion
    final Point n = new Point(pt.getX()*f, pt.getY()*f);
    return new Vector(n);
  }
  
  public Vector normalize() {
    return scale( 1.0f / magnitude() );
  }
  
  public Point add(Point that) {
    return this.pt.add(that);
  }
  
  public Point sub(Point that) {
    return this.pt.sub(that);
  }
  
  @Override
  public String toString() { return pt.toString(); }
}




Java Source Code List

com.asolutions.widget.RowLayout.java
org.kleemann.diceprobabilities.Check.java
org.kleemann.diceprobabilities.ConstantCurrentDicePile.java
org.kleemann.diceprobabilities.CurrentDicePile.java
org.kleemann.diceprobabilities.DiceSet.java
org.kleemann.diceprobabilities.MainActivity.java
org.kleemann.diceprobabilities.PoolDicePile.java
org.kleemann.diceprobabilities.TargetPool.java
org.kleemann.diceprobabilities.Target.java
org.kleemann.diceprobabilities.distribution.AbstractDistribution.java
org.kleemann.diceprobabilities.distribution.CachedCumulativeDistribution.java
org.kleemann.diceprobabilities.distribution.ConstantDistribution.java
org.kleemann.diceprobabilities.distribution.CritDistribution.java
org.kleemann.diceprobabilities.distribution.DeathZoneDieDistribution.java
org.kleemann.diceprobabilities.distribution.DieDistribution.java
org.kleemann.diceprobabilities.distribution.Distribution.java
org.kleemann.diceprobabilities.distribution.DogslicerDistribution.java
org.kleemann.diceprobabilities.distribution.ScaleCumulativeDistribution.java
org.kleemann.diceprobabilities.distribution.SumDistribution.java
org.kleemann.diceprobabilities.graph.GraphView.java
org.kleemann.diceprobabilities.graph.Interpolate.java
org.kleemann.diceprobabilities.graph.Point.java
org.kleemann.diceprobabilities.graph.Vector.java
org.kleemann.diceprobabilities.special.AbstractSpecial.java
org.kleemann.diceprobabilities.special.CritSpecial.java
org.kleemann.diceprobabilities.special.DeathZoneSpecial.java
org.kleemann.diceprobabilities.special.DogslicerSpecial.java
org.kleemann.diceprobabilities.special.FailureSpecial.java
org.kleemann.diceprobabilities.special.ForcedRerollSpecial.java
org.kleemann.diceprobabilities.special.ModifyEachDieSpecial.java
org.kleemann.diceprobabilities.special.NormalSpecial.java
org.kleemann.diceprobabilities.special.SecondChanceSpecial.java
org.kleemann.diceprobabilities.special.SpecialSpinner.java
org.kleemann.diceprobabilities.special.Special.java