point.js
Summary
No overview generated for 'point.js'
Class Summary
|
Point |
A class representing a two-dimensional point. |
function Point(x, y){
this.x = parseFloat(x);
this.y = parseFloat(y);
}
Point.prototype.dist = function(p){
return Math.sqrt(Math.pow(this.y-p.y,2) + Math.pow(this.x-p.x,2)) ;
}
Point.prototype.equals = function(p){
if (this.x == p.x && this.y == p.y) {return true;}
return false;
}
Point.prototype.minus = function(p){
return new Point(this.x-p.x, this.y-p.y);
}
Point.prototype.plus = function(p){
return new Point(this.x+p.x, this.y+p.y);
}
Point.prototype.dividedBy = function(c){
if (c != 0) {
return new Point(this.x/c, this.y/c);
}
var e = new Mb_exception("Point.dividedBy: Division by zero");
return false;
}
Point.prototype.times = function(c){
return new Point(this.x*c, this.y*c);
}
Point.prototype.round = function(numOfDigits){
return new Point(roundToDigits(this.x, numOfDigits), roundToDigits(this.y, numOfDigits));
}
Point.prototype.toString = function(){
return "(" + this.x + ", " + this.y + ")";
}
function mapToReal(frameName, aPoint) {
var v;
if (typeof(mb_mapObj) == 'object') v = makeClickPos2RealWorldPos(frameName, aPoint.x, aPoint.y);
else if (typeof(parent.mb_mapObj) == 'object') v = parent.makeClickPos2RealWorldPos(frameName, aPoint.x, aPoint.y);
else alert('where am i?');
return new Point(v[0], v[1]);
}
function realToMap(frameName, aPoint) {
var v;
if (typeof(mb_mapObj) == 'object') {
v = makeRealWorld2mapPos(frameName, aPoint.x, aPoint.y);
}
else if (typeof(parent.mb_mapObj) == 'object') {
v = parent.makeRealWorld2mapPos(frameName, aPoint.x, aPoint.y);
}
else {
var e = new Mb_exception('Point.realToMap:where am i?');
}
return new Point(v[0], v[1]);
}
function mb_calcExtent(frameName, min, max) {
var ind;
if (typeof(mb_mapObj) == 'object') {
ind = getMapObjIndexByName(frameName);
}
else if (typeof(parent.mb_mapObj) == 'object') {
ind = parent.getMapObjIndexByName(frameName);
}
else {
var e = new Mb_exception('Point.mb_calcExtent: function getMapObjIndexByName not found');
}
var extent = max.minus(min);
var center = extent.dividedBy(2).plus(min);
var relation_px_x = mb_mapObj[ind].width / mb_mapObj[ind].height;
var relation_px_y = mb_mapObj[ind].height / mb_mapObj[ind].width;
var relation_bbox_x = extent.x / extent.y;
var new_min;
var new_max;
if(relation_bbox_x <= relation_px_x){
new_min = new Point(center.x - relation_px_x * extent.y / 2, min.y);
new_max = new Point(center.x + relation_px_x * extent.y / 2, max.y);
}
else if(relation_bbox_x > relation_px_x){
new_min = new Point(min.x, center.y - relation_px_y * extent.x / 2);
new_max = new Point(max.x, center.y + relation_px_y * extent.x / 2);
}
mb_mapObj[ind].extent = new_min.x +","+ new_min.y +","+ new_max.x +","+ new_max.y;
}
function roundToDigits(aFloat, numberOfDigits) {
return Math.round(aFloat*Math.pow(10, parseInt(numberOfDigits)))/Math.pow(10, parseInt(numberOfDigits));
}
Documentation generated by
JSDoc on Wed Aug 8 10:35:22 2007