add default vector implementation

As requested by sk89q in <https://github.com/SpongePowered/Sponge/pull/29>.
Ya, I'm plenty aware of the use of Java here.   Thanks.
The point was, if the members x and y were volatile,  then   x*x + y+y    is not safe.
I didn't check if the members were volatile.  I would't be surprised if they were.
The reference to the article was to provide some background.

Date: Mon, 1 Dec 2014 13:32:14 -0800
From: notifications@github.com
To: SpongeAPI@noreply.github.com
CC: sibomots@outlook.com
Subject: Re: [SpongeAPI] add default vector implementation (#196)

In src/main/java/org/spongepowered/api/math/SpongeVector2d.java:

> +    }
> +
> +    @Override
> +    public double lengthSquared() {
> +        return x * x + y * y;
> +    }
> +
> +    @Override
> +    public double length() {
> +        return Math.sqrt(x * x + y * y);
> +    }
> +
> +    @Override
> +    public Vector2d normalize() {
> +        double length = Math.sqrt(x * x + y * y);
> +        return new SpongeVector2d(x / length, y / length);


return *ptr * *ptr;

We are using Java here not C.



—
Reply to this email directly or view it on GitHub.

  
    
    
  
  
 		 	   		  =