Skip to content

Commit

Permalink
补注释
Browse files Browse the repository at this point in the history
  • Loading branch information
techird committed Aug 4, 2014
1 parent 62a9134 commit 6987d2e
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example/geometry.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
var path1 = new Path().stroke('blue').translate(-300, 0);
var path2 = new Path().stroke('red', 5).translate(-300, 0);

var paper = new Paper(document.body);
var paper = new Paper(document.body).setHeight(800);
paper.addShapes([path1, path2]);

var pathData2 = 'M615.992,227.397c0,48.272-43.234,87.405-96.565,87.405 s-96.565-39.132-96.565-87.405c0-22.737,9.631-33.72,25.351-49.267c5.705-5.642-7.917-57.699-0.763-61.832 c5.962-3.445,36.82,36.75,43.511,34.351c40.458-14.504,51.562-2.07,61.069,0.763c11.853,3.532,43.345-29.261,52.672-22.137c7.952,6.074-8.23,44.582-2.784,52.659C610.847,195.18,615.992,210.745,615.992,227.397z';
Expand Down
1 change: 0 additions & 1 deletion src/animate/motionanimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ define(function(require) {
if (this.doRotate) target.setRotate(point.tan.getAngle());
}
});
this.updatePath(path);

/**
* @property doRotate
Expand Down
144 changes: 139 additions & 5 deletions src/graphic/bezierpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@ define(function(require, exports, module) {

/**
* @class kity.BezierPoint
*
* @description 表示一个贝塞尔点
* 一个贝塞尔点由顶点坐标(曲线经过的点)、前方控制点、后方控制点表示
*/
var BezierPoint = require('core/class').createClass('BezierPoint', {

/**
* @constructor
* @for kity.BezierPoint
*
* @description 创建一个具有默认顶点坐标的贝塞尔点,两个控制点的坐标和顶点一致
*
* @param {Number} x 顶点的 x 坐标
* @param {Number} y 顶点的 y 坐标
* @param {Boolean} isSmooth 指示当前贝塞尔点是否光滑,光滑会约束顶点和两个控制点共线
*/
constructor: function(x, y, isSmooth) {

//顶点
Expand All @@ -30,6 +43,13 @@ define(function(require, exports, module) {

},

/**
* @method clone()
* @for kity.BezierPoint
* @description 返回贝塞尔点的一份拷贝
*
* @grammar clone() => {kity.BezierPoint}
*/
clone: function() {

var newPoint = new BezierPoint(),
Expand All @@ -44,12 +64,23 @@ define(function(require, exports, module) {
tmp = this.getBackward();
newPoint.setBackward(tmp.x, tmp.y);

newPoint.setSmooth(newPoint.isSmooth());
newPoint.setSymReflaction(this.isSymReflaction);
newPoint.setSmooth(this.isSmooth());

return newPoint;

},

/**
* @method setVertex()
* @for kity.BezierPoint
* @description 设置贝塞尔点的顶点坐标,注意,控制点的坐标不会跟着变化。希望控制点的坐标跟着变化,请用 moveTo() 方法
*
* @grammar setVertex(x, y) => {this}
*
* @param {Number} x 顶点的 x 坐标
* @param {Number} y 顶点的 y 坐标
*/
setVertex: function(x, y) {

this.vertex.setPoint(x, y);
Expand All @@ -60,6 +91,17 @@ define(function(require, exports, module) {

},

/**
* @method moveTo()
* @for kity.BezierPoint
* @description 同步移动整个贝塞尔点,使顶点的移动到指定的坐标中。控制点的位置相对顶点坐标固定。
*
* @grammar moveTo() => {this}
*
* @param {Number} x 顶点的目标 x 坐标
* @param {Number} y 顶点的目标 y 坐标
*
*/
moveTo: function(x, y) {

var oldForward = this.forward.getPoint(),
Expand All @@ -81,6 +123,16 @@ define(function(require, exports, module) {

},

/**
* @method setForward()
* @for kity.BezierPoint
* @description 设置前方控制点的位置,如果贝塞尔点光滑,后方控制点会跟着联动
*
* @grammar setForward(x, y) => {this}
*
* @param {Number} x 前方控制点的 x 坐标
* @param {Number} y 前方控制点的 y 坐标
*/
setForward: function(x, y) {

this.forward.setPoint(x, y);
Expand All @@ -90,10 +142,21 @@ define(function(require, exports, module) {
this.updateAnother(this.forward, this.backward);
}
this.update();
this.lastControlPointSet = this.forward;
return this;

},

/**
* @method setBackward()
* @for kity.BezierPoint
* @description 设置后方控制点的位置,如果贝塞尔点光滑,前方控制点会跟着联动
*
* @grammar setBackward(x, y) => {this}
*
* @param {Number} x 后方控制点的 x 坐标
* @param {Number} y 后方控制点的 y 坐标
*/
setBackward: function(x, y) {

this.backward.setPoint(x, y);
Expand All @@ -104,56 +167,127 @@ define(function(require, exports, module) {
}

this.update();
this.lastControlPointSet = this.backward;
return this;

},

/**
* @method setSymReflaction()
* @for kity.BezierPoint
* @description 设定是否镜像两个控制点的位置
*
* @grammar setSymReflaction(value) => {this}
*
* @param {boolean} value 如果设置为 true,且贝塞尔点光滑,两个控制点离顶点的距离相等
*/
setSymReflaction: function(value) {
this.symReflaction = value;
if (this.smooth) this.setSmooth(true);
return this;
},

/**
* @method isSymReflaction()
* @for kity.BezierPoint
* @description 当前贝塞尔点的两个控制点是否被镜像约束
*
* @grammar isSymReflaction() => {boolean}
*/
isSymReflaction: function() {
return this.symReflaction;
},

/**
* @private
*
* 根据前方控制点或后方控制点更新另一方
*/
updateAnother: function(p, q) {
var v = this.getVertex(),
pv = Vector.fromPoints(p.getPoint(), v),
vq = Vector.fromPoints(v, q.getPoint());
vq = pv.normalize(this.isSymReflaction() ? pv.length() : vq.length());
q.setPoint(v.x + vq.x, v.y + vq.y);
return this;
},

/**
* @method setSmooth()
* @for kity.BezierPoint
* @description 设置贝塞尔点是否光滑,光滑会约束顶点和两个控制点共线
*
* @param {Boolean} isSmooth 设置为 true 让贝塞尔点光滑
*/
setSmooth: function(isSmooth) {
var lc;

this.smooth = !!isSmooth;

if (this.smooth && (lc = this.lastControlPointSet)) {
this.updateAnother(lc, lc == this.forward ? this.backward : this.forward);
}

return this;

},

/**
* @method isSmooth()
* @for kity.BezierPoint
* @description 判断贝塞尔点是否光滑
*
* @grammar isSmooth() => {boolean}
*/
isSmooth: function() {
return this.smooth;
},

/**
* @method getVertex()
* @for kity.BezierPoint
* @description 获得当前贝塞尔点的顶点
*
* @grammar getVertex() => {kity.ShapePoint}
*/
getVertex: function() {

return this.vertex.getPoint();

},

/**
* @method getForward()
* @for kity.BezierPoint
* @description 获得当前贝塞尔点的前方控制点
*
* @grammar getForward() => {kity.ShapePoint}
*/
getForward: function() {

return this.forward.getPoint();

},


/**
* @method getBackward()
* @for kity.BezierPoint
* @description 获得当前贝塞尔点的后方控制点
*
* @grammar getBackward() => {kity.ShapePoint}
*/
getBackward: function() {

return this.backward.getPoint();

},

isSmooth: function() {
return this.smooth;
},

/**
* @private
*
* 联动更新相关的贝塞尔曲线
*/
update: function() {

if (!this.container) {
Expand Down
13 changes: 8 additions & 5 deletions src/graphic/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ define(function(require, exports, module) {
* @constructor
* @for kity.Circle
*
* @param {[type]} radius [description]
* @param {[type]} cx [description]
* @param {[type]} cy [description]
*
* @return {[type]} [description]
* @param {Number} radius 半径
* @param {Number} cx 圆心 x 坐标
* @param {Number} cy 圆心 y 坐标
*/
constructor: function(radius, cx, cy) {
this.callBase(radius, radius, cx, cy);
},

/**
* @method
* @for kity.Circle
* @description 获取原型的半径
*/
getRadius: function() {
return this.getRadiusX();
},
Expand Down
6 changes: 6 additions & 0 deletions src/graphic/clip.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @fileOverview
*
* 支持图形剪辑
*/

define(function(require, exports, module) {
var Class = require('core/class');
var Shape = require('graphic/shape');
Expand Down

0 comments on commit 6987d2e

Please sign in to comment.