Permalink
Browse files

Gallery Build Tag: gallery-2011.04.27-17-14

  • Loading branch information...
1 parent b1c759b commit 7ebb2113e5a941a8f65fdb34ac3e9640759fe772 YUI Builder committed Apr 27, 2011
@@ -56,7 +56,7 @@ ComplexNumber.prototype =
*/
magnitude: function()
{
- return ComplexMath.abs(this);
+ return Math.sqrt(this.r*this.r + this.i*this.i);
},
/**
@@ -175,6 +175,34 @@ ComplexNumber.prototype =
return this;
},
+ /**
+ * Negates the imaginary part.
+ * @chainable
+ */
+ conjugate: function()
+ {
+ failIfConstant(this);
+
+ this.i = - this.i;
+
+ return this;
+ },
+
+ /**
+ * Rotates the number around the origin by the specified angle in radians.
+ * @param angle {number}
+ * @chainable
+ */
+ rotate: function(
+ /* float */ angle)
+ {
+ failIfConstant(this);
+
+ this.multiply(ComplexNumber.fromPolar(1, angle));
+
+ return this;
+ },
+
toString: function()
{
function i(v)
@@ -396,6 +424,48 @@ var ComplexMath =
}
},
+ /**
+ * @param v {number}
+ * @return {number} phase of the argument
+ */
+ phase: function(v)
+ {
+ if (ComplexMath.isComplexNumber(v))
+ {
+ return new ComplexNumber(Math.atan2(v.i, v.r), 0);
+ }
+ else
+ {
+ return new ComplexNumber();
+ }
+ },
+
+ /**
+ * @param v {number}
+ * @return {number} complex conjugate of the argument
+ */
+ conjugate: function(v)
+ {
+ if (ComplexMath.isComplexNumber(v))
+ {
+ return new ComplexNumber(v.r, -v.i);
+ }
+ else
+ {
+ return new ComplexNumber(v, 0);
+ }
+ },
+
+ /**
+ * @param v {number}
+ * @param a {number} angle in radians
+ * @return {number} phase of the argument
+ */
+ rotate: function(v,a)
+ {
+ return ComplexMath.multiply(v, ComplexNumber.fromPolar(1, a));
+ },
+
/**
* @param v {number}
* @return {number} inverse hyperbolic cosine of the argument
@@ -532,7 +602,23 @@ var ComplexMath =
*/
pow: function(v, e)
{
- return ComplexMath.exp(ComplexMath.multiply(ComplexMath.log(v), e));
+ var c1 = ComplexMath.isComplexNumber(v);
+ if ((c1 && v.r === 0 && v.i === 0) || (!c1 && v === 0))
+ {
+ var c2 = ComplexMath.isComplexNumber(e);
+ if ((c2 && e.r === 0 && e.i === 0) || (!c2 && e === 0))
+ {
+ return new ComplexNumber(1); // 0 ^ 0
+ }
+ else
+ {
+ return new ComplexNumber(); // 0 ^ x, x != 0
+ }
+ }
+ else
+ {
+ return ComplexMath.exp(ComplexMath.multiply(ComplexMath.log(v), e));
+ }
},
/**
@@ -623,4 +709,4 @@ var ComplexMath =
Y.ComplexMath = ComplexMath;
-}, 'gallery-2011.03.16-21-24' ,{requires:['gallery-math']});
+}, 'gallery-2011.04.27-17-14' ,{requires:['gallery-math']});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -56,7 +56,7 @@ ComplexNumber.prototype =
*/
magnitude: function()
{
- return ComplexMath.abs(this);
+ return Math.sqrt(this.r*this.r + this.i*this.i);
},
/**
@@ -175,6 +175,34 @@ ComplexNumber.prototype =
return this;
},
+ /**
+ * Negates the imaginary part.
+ * @chainable
+ */
+ conjugate: function()
+ {
+ failIfConstant(this);
+
+ this.i = - this.i;
+
+ return this;
+ },
+
+ /**
+ * Rotates the number around the origin by the specified angle in radians.
+ * @param angle {number}
+ * @chainable
+ */
+ rotate: function(
+ /* float */ angle)
+ {
+ failIfConstant(this);
+
+ this.multiply(ComplexNumber.fromPolar(1, angle));
+
+ return this;
+ },
+
toString: function()
{
function i(v)
@@ -396,6 +424,48 @@ var ComplexMath =
}
},
+ /**
+ * @param v {number}
+ * @return {number} phase of the argument
+ */
+ phase: function(v)
+ {
+ if (ComplexMath.isComplexNumber(v))
+ {
+ return new ComplexNumber(Math.atan2(v.i, v.r), 0);
+ }
+ else
+ {
+ return new ComplexNumber();
+ }
+ },
+
+ /**
+ * @param v {number}
+ * @return {number} complex conjugate of the argument
+ */
+ conjugate: function(v)
+ {
+ if (ComplexMath.isComplexNumber(v))
+ {
+ return new ComplexNumber(v.r, -v.i);
+ }
+ else
+ {
+ return new ComplexNumber(v, 0);
+ }
+ },
+
+ /**
+ * @param v {number}
+ * @param a {number} angle in radians
+ * @return {number} phase of the argument
+ */
+ rotate: function(v,a)
+ {
+ return ComplexMath.multiply(v, ComplexNumber.fromPolar(1, a));
+ },
+
/**
* @param v {number}
* @return {number} inverse hyperbolic cosine of the argument
@@ -532,7 +602,23 @@ var ComplexMath =
*/
pow: function(v, e)
{
- return ComplexMath.exp(ComplexMath.multiply(ComplexMath.log(v), e));
+ var c1 = ComplexMath.isComplexNumber(v);
+ if ((c1 && v.r === 0 && v.i === 0) || (!c1 && v === 0))
+ {
+ var c2 = ComplexMath.isComplexNumber(e);
+ if ((c2 && e.r === 0 && e.i === 0) || (!c2 && e === 0))
+ {
+ return new ComplexNumber(1); // 0 ^ 0
+ }
+ else
+ {
+ return new ComplexNumber(); // 0 ^ x, x != 0
+ }
+ }
+ else
+ {
+ return ComplexMath.exp(ComplexMath.multiply(ComplexMath.log(v), e));
+ }
},
/**
@@ -623,4 +709,4 @@ var ComplexMath =
Y.ComplexMath = ComplexMath;
-}, 'gallery-2011.03.16-21-24' ,{requires:['gallery-math']});
+}, 'gallery-2011.04.27-17-14' ,{requires:['gallery-math']});
@@ -0,0 +1,116 @@
+YUI.add('gallery-geo', function(Y) {
+
+/*global YUI*/
+//select * from geo.places where woeid in (select place.woeid from flickr.places where (lat,lon) in(select latitude,longitude from ip.location where ip="209.131.62.113"))
+/*
+ * Copyright (c) 2011 Yahoo! Inc. All rights reserved.
+ * Written by Nicholas C. Zakas, nczonline.net
+ */
+
+var IP_URL = "http://www.geoplugin.net/json.gp?jsoncallback=";
+
+/**
+ * Geolocation API
+ * @module gallery-geo
+ */
+
+/*(intentionally not documented)
+ * Tries to get the current position by using the native geolocation API.
+ * If the user denies permission, then no further attempt is made to get
+ * the location. If an error occurs, then an attempt is made to get the
+ * location information by IP address.
+ * @param callback {Function} The callback function to call when the
+ * request is complete. The object passed into the request has
+ * four properties: success (true/false), coords (an object),
+ * timestamp, and source ("native" or "geoplugin").
+ * @param scope {Object} (Optional) The this value for the callback function.
+ */
+function getCurrentPositionByAPI(callback, scope){
+ navigator.geolocation.getCurrentPosition(
+ function(data){
+ callback.call(scope, {
+ success: true,
+ coords: {
+ latitude: data.coords.latitude,
+ longitude: data.coords.longitude,
+ accuracy: data.coords.accuracy,
+ altitude: data.coords.altitude,
+ altitudeAccuracy: data.coords.altitudeAccuracy,
+ heading: data.coords.heading,
+ speed: data.coords.speed
+ },
+ timestamp: data.timestamp,
+ source: "native"
+ });
+ },
+ function(error){
+ if (error.code == 1) { //user denied permission, so don't do anything
+ callback.call(scope, { success: false, denied: true });
+ } else { //try Geo IP Lookup instead
+ getCurrentPositionByGeoIp(callback,scope);
+ }
+ }
+ );
+}
+
+/*(intentionally not documented)
+ * Tries to get the current position by using the IP address.
+ * @param callback {Function} The callback function to call when the
+ * request is complete. The object passed into the request has
+ * four properties: success (true/false), coords (an object),
+ * timestamp, and source ("native" or "geoplugin").
+ * @param scope {Object} (Optional) The this value for the callback function.
+ */
+function getCurrentPositionByGeoIP(callback, scope){
+
+ //Try to get by IP address
+ Y.jsonp(IP_URL, {
+ format: function(url, proxy){
+ return url + proxy;
+ },
+ on: {
+ success: function(response){
+ callback.call(scope, {
+ success: true,
+ coords: {
+ latitude: parseFloat(response.geoplugin_latitude),
+ longitude: parseFloat(response.geoplugin_longitude),
+ accuracy: Infinity //TODO: Figure out better value
+ },
+ timestamp: +new Date(),
+ source: "geoplugin"
+ });
+ },
+ failure: function(){
+ callback.call(scope, { success: false });
+ }
+ }
+ });
+
+}
+
+/**
+ * Geolocation API
+ * @class Geo
+ * @static
+ */
+Y.Geo = {
+
+ /**
+ * Get the current position. This tries to use the native geolocation
+ * API if available. Otherwise it uses the GeoPlugin site to do an
+ * IP address lookup.
+ * @param callback {Function} The callback function to call when the
+ * request is complete. The object passed into the request has
+ * four properties: success (true/false), coords (an object),
+ * timestamp, and source ("native" or "geoplugin").
+ * @param scope {Object} (Optional) The this value for the callback function.
+ */
+ getCurrentPosition: navigator.geolocation ?
+ getCurrentPositionByAPI :
+ getCurrentPositionByGeoIP
+
+};
+
+
+}, 'gallery-2011.04.27-17-14' ,{requires:['jsonp']});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 7ebb211

Please sign in to comment.