123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- if(!dojo._hasResource["dojox.drawing.util.common"]){
- dojo._hasResource["dojox.drawing.util.common"] = true;
- dojo.provide("dojox.drawing.util.common");
- dojo.require("dojox.math.round");
- (function(){
-
- var uidMap = {};
- var start = 0;
- dojox.drawing.util.common = {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- radToDeg: function(/*Numer*/n){
-
-
- return (n*180)/Math.PI;
- },
-
- degToRad: function(/*Numer*/n){
-
-
- return (n*Math.PI)/180;
- },
-
- angle: function(/*EventObject*/obj, /* ? Float */snap){
-
-
-
-
-
-
-
-
-
- if(snap){
- snap = snap/180;
- var radians = this.radians(obj),
- seg = Math.PI * snap,
- rnd = dojox.math.round(radians/seg),
- new_radian = rnd*seg;
- return dojox.math.round(this.radToDeg(new_radian));
-
- }else{
- return this.radToDeg(this.radians(obj));
- }
- },
-
- oppAngle: function(/*Angle*/ang){
- (ang+=180) > 360 ? ang = ang - 360 : ang;
- return ang;
- },
-
- radians: function(/*EventObject*/o){
-
-
-
-
-
- return Math.atan2(o.start.y-o.y,o.x-o.start.x);
- },
-
- length: function(/*EventObject*/o){
-
-
-
-
- return Math.sqrt(Math.pow(o.start.x-o.x, 2)+Math.pow(o.start.y-o.y, 2));
- },
-
- lineSub: function(/*Number*/x1, /*Number*/y1, /*Number*/x2, /*Number*/y2, /*Number*/amt){
-
-
-
-
-
-
- var len = this.distance(this.argsToObj.apply(this, arguments));
- len = len < amt ? amt : len;
- var pc = (len-amt)/len;
- var x = x1 - (x1-x2) * pc;
- var y = y1 - (y1-y2) * pc;
- return {x:x, y:y};
- },
-
- argsToObj: function(){
-
-
-
-
-
- var a = arguments;
- if(a.length < 4){ return a[0]; }
- return {
- start:{
- x:a[0],
- y:a[1]
- },
- x:a[2],
- y:a[3]
-
- };
- },
-
- distance: function(/*EventObject or x1,y1,x2,y2*/){
-
-
-
-
-
- var o = this.argsToObj.apply(this, arguments);
- return Math.abs(Math.sqrt(Math.pow(o.start.x-o.x, 2)+Math.pow(o.start.y-o.y, 2)));
- },
-
- slope:function(/*Object*/p1, /*Object*/p2){
-
-
- if(!(p1.x-p2.x)){ return 0; }
- return ((p1.y-p2.y)/(p1.x-p2.x));
- },
-
- pointOnCircle: function(/*Number*/cx, /*Number*/cy, /*Number*/radius, /*Number*/angle){
-
-
-
-
-
- var radians = angle * Math.PI / 180.0;
- var x = radius * Math.cos(radians);
- var y = radius * Math.sin(radians);
- return {
- x:cx+x,
- y:cy-y
- };
- },
-
- constrainAngle: function(/*EventObject*/obj, /*Number*/min, /*Number*/max){
-
-
-
-
-
- var angle = this.angle(obj);
- if(angle >= min && angle <= max){
- return obj;
- }
- var radius = this.length(obj);
- var new_angle = angle > max ? max : min - angle < 100 ? min : max;
- return this.pointOnCircle(obj.start.x,obj.start.y,radius, new_angle);
- },
-
- snapAngle: function(/*EventObject*/obj, /*Float*/ca){
-
-
-
-
-
-
-
-
-
- var radians = this.radians(obj),
- radius = this.length(obj),
- seg = Math.PI * ca,
- rnd = Math.round(radians/seg),
- new_radian = rnd*seg,
- new_angle = this.radToDeg(new_radian),
- pt = this.pointOnCircle(obj.start.x,obj.start.y,radius,new_angle);
- return pt;
- },
-
-
- idSetStart: function(num){
- start=num;
- },
-
- uid: function(/* ? String */str){
-
-
-
-
-
-
-
- str = str || "shape";
- uidMap[str] = uidMap[str]===undefined ? start : uidMap[str] + 1;
- return str + uidMap[str];
- },
-
- abbr: function(type){
-
-
-
- return type.substring(type.lastIndexOf(".")+1).charAt(0).toLowerCase()
- + type.substring(type.lastIndexOf(".")+2);
- },
- mixin: function(o1, o2){
-
-
- },
-
- objects:{},
- register: function(/*Object*/obj){
-
-
-
-
-
-
- this.objects[obj.id] = obj;
- },
- byId: function(/*String*/id){
-
-
-
- return this.objects[id];
- },
- attr: function(/* Object */ elem, /* property */ prop, /* ? value */ value, squelchErrors){
-
-
-
-
- if(!elem){ return false; }
- try{
-
-
-
- if(elem.shape && elem.util){
- elem = elem.shape;
- }
-
- if(!value && prop=="id" && elem.target){
-
- var n = elem.target;
- while(!dojo.attr(n, "id")){
- n = n.parentNode;
- }
- return dojo.attr(n, "id");
- }
-
- if(elem.rawNode || elem.target){
- var args = Array.prototype.slice.call(arguments);
- args[0] = elem.rawNode || elem.target;
- return dojo.attr.apply(dojo, args);
- }
- return dojo.attr(elem, "id");
-
-
-
- }catch(e){
- if(!squelchErrors){
-
-
-
-
- }
- return false;
- }
- }
- };
-
- })();
- }
|