TransitionCompass.js
上传用户:ahit0551
上传日期:2009-04-15
资源大小:2345k
文件大小:4k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /**
  2.  * <p>Title:  </p>
  3.  * <p>Description: </p>
  4.  * <p>Copyright: Copyright (c) xio.name 2006</p>
  5.  * @author xio
  6.  */
  7. function TransitionCompass() {
  8. }
  9. TransitionCompass.getOffset = function (fromMetaNodeModel, toMetaNodeModel) {
  10.     if ((!fromMetaNodeModel) || (!toMetaNodeModel)) {
  11.         return null;
  12.     }
  13.     //
  14.     var fromPoint = fromMetaNodeModel.getPosition();
  15.     var fromX = fromPoint.getX();
  16.     var fromY = fromPoint.getY();
  17.     var fromSize = fromMetaNodeModel.getSize();
  18.     var fromWidth = fromSize.getWidth();
  19.     var fromHeight = fromSize.getHeight();
  20.     var fromMinX = fromX;
  21.     var fromMinY = fromY;
  22.     var fromMaxX = fromX + fromWidth;
  23.     var fromMaxY = fromY + fromHeight;
  24.     //
  25.     var toPoint = toMetaNodeModel.getPosition();
  26.     var toX = toPoint.getX();
  27.     var toY = toPoint.getY();
  28.     var toSize = toMetaNodeModel.getSize();
  29.     var toWidth = toSize.getWidth();
  30.     var toHeight = toSize.getHeight();
  31.     var toMinX = toX;
  32.     var toMinY = toY;
  33.     var toMaxX = toX + toWidth;
  34.     var toMaxY = toY + toHeight;
  35. //
  36.     if (fromMaxY <= toMinY) {
  37.         if ((fromMaxX >= toMinX) && (fromMinX <= toMaxX)) {
  38.             var min = Math.max(fromMinX, toMinX);
  39.             var max = Math.min(fromMaxX, toMaxX);
  40.             var x = Math.round((min + max) / 2);
  41.             return [new Point(x - fromX, fromMaxY - fromY), new Point(x - toX, toMinY - toY)];
  42.         } else {
  43.             if (fromMinX > toMaxX) {
  44.                 return [new Point(fromMinX - fromX, fromMaxY - fromY), new Point(toMaxX - toX, toMinY - toY)];
  45.             } else {
  46.                 if (fromMaxX < toMinX) {
  47.                     return [new Point(fromMaxX - fromX, fromMaxY - fromY), new Point(toMinX - toX, toMinY - toY)];
  48.                 }
  49.             }
  50.         }
  51.     }
  52.     //
  53.     if (fromMinY >= toMaxY) {
  54.         if ((fromMaxX >= toMinX) && (fromMinX <= toMaxX)) {
  55.             var min = Math.max(fromMinX, toMinX);
  56.             var max = Math.min(fromMaxX, toMaxX);
  57.             var x = Math.round((min + max) / 2);
  58.             return [new Point(x - fromX, fromMinY - fromY), new Point(x - toX, toMaxY - toY)];
  59.         } else {
  60.             if (fromMinX > toMaxX) {
  61.                 return [new Point(fromMinX - fromX, fromMinY - fromY), new Point(toMaxX - toX, toMaxY - toY)];
  62.             } else {
  63.                 if (fromMaxX < toMinX) {
  64.                     return [new Point(fromMaxX - fromX, fromMinY - fromY), new Point(toMinX - toX, toMaxY - toY)];
  65.                 }
  66.             }
  67.         }
  68.     }
  69.     //
  70.     if ((fromMaxY > toMinY) && (fromMinY < toMaxY)) {
  71.         var min = Math.max(fromMinY, toMinY);
  72.         var max = Math.min(fromMaxY, toMaxY);
  73.         var y = Math.round((min + max) / 2);
  74.         if ((fromMaxX >= toMinX) && (fromMinX <= toMaxX)) {
  75.             var min = Math.max(fromMinX, toMinX);
  76.             var max = Math.min(fromMaxX, toMaxX);
  77.             var x = Math.round((min + max) / 2);
  78.             return [new Point(x - fromX, y - fromY), new Point(x - toX, y - toY)];
  79.         } else {
  80.             if (fromMinX > toMaxX) {
  81.                 return [new Point(fromMinX - fromX, y - fromY), new Point(toMaxX - toX, y - toY)];
  82.             } else {
  83.                 if (fromMaxX < toMinX) {
  84.                     return [new Point(fromMaxX - fromX, y - fromY), new Point(toMinX - toX, y - toY)];
  85.                 }
  86.             }
  87.         }
  88.     }
  89.     //
  90.     return [new Point(Math.round(fromWidth / 2), fromHeight), new Point(Math.round(toWidth / 2), 0)];
  91. };
  92. TransitionCompass.getFromOffset = function (fromMetaNodeModel, toMetaNodeModel) {
  93.     if ((!fromMetaNodeModel) || (!toMetaNodeModel)) {
  94.         return null;
  95.     }
  96.     //
  97.     var size = fromMetaNodeModel.getSize();
  98.     return new Point(size.getWidth() / 2, size.getHeight());
  99. };
  100. TransitionCompass.getToOffset = function (fromMetaNodeModel, toMetaNodeModel) {
  101.     if ((fromMetaNodeModel == null) || (toMetaNodeModel == null)) {
  102.         return null;
  103.     }
  104.     var size = toMetaNodeModel.getSize();
  105.     return new Point(size.getWidth() / 2, 0);
  106. };
  107. TransitionCompass.convertOffsetToPoint = function (metaNodeModel, offset) {
  108.     var point = metaNodeModel.getPosition();
  109.     return new Point(point.getX() + offset.getX(), point.getY() + offset.getY());
  110. };