Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 47 additions & 13 deletions src/app/core/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,33 +168,49 @@ thin.core.Line.prototype.getCoordinate = function() {
};


/**
* @param {number} left
* @private
*/
thin.core.Line.prototype.setLeft_ = function(left) {
this.left_ = thin.numberWithPrecision(left - this.getParentTransLateX());
};


/**
* @param {number} left
*/
thin.core.Line.prototype.setLeft = function(left) {
left = thin.numberWithPrecision(left - this.getParentTransLateX());
this.left_ = left;
this.setX1(left);
this.setX2(left + this.getWidth());
this.setLeft_(left);
this.setX1(this.left_);
this.setX2(this.left_ + this.getWidth());
};


/**
* @param {number} top
* @private
*/
thin.core.Line.prototype.setTop_ = function(top) {
this.top_ = thin.numberWithPrecision(top - this.getParentTransLateY());
};


/**
* @param {number} top
*/
thin.core.Line.prototype.setTop = function(top) {
top = thin.numberWithPrecision(top - this.getParentTransLateY());
this.top_ = top;
this.setTop_(top);

var directionType = thin.core.Line.DIRECTION_;
var direction = this.getDirection();

if (direction == directionType.Y1) {
var y1 = top;
var y2 = top + this.getHeight();
var y1 = this.top_;
var y2 = this.top_ + this.getHeight();
} else if (direction == directionType.Y2) {
var y1 = top + this.getHeight();
var y2 = top;
var y1 = this.top_ + this.getHeight();
var y2 = this.top_;
}
this.setY1(y1);
this.setY2(y2);
Expand All @@ -203,19 +219,37 @@ thin.core.Line.prototype.setTop = function(top) {

/**
* @param {number} width
* @private
*/
thin.core.Line.prototype.setWidth = function(width) {
thin.core.Line.prototype.setWidth_ = function(width) {
width = thin.numberWithPrecision(width);
this.width_ = width;
this.setX2(this.getLeft() + width);
};


/**
* @param {number} width
*/
thin.core.Line.prototype.setWidth = function(width) {
this.setWidth_(width);
this.setX2(this.getLeft() + this.width_);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.getLeft() じゃなくて this.left_ で良いのでは。他の箇所も this.top_ ってやってるし、メソッドじゃなくて変数を直接取得する方に統一した方が良さそう。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getter での呼び出しは translate 値を考慮した値を返すという意味があるのです。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど難しい。

};


/**
* @param {number} height
* @private
*/
thin.core.Line.prototype.setHeight_ = function(height) {
this.height_ = thin.numberWithPrecision(height);
};


/**
* @param {number} height
*/
thin.core.Line.prototype.setHeight = function(height) {
this.height_ = thin.numberWithPrecision(height);
this.setHeight_(height);
this.setTop(this.getTop());
};

Expand Down
8 changes: 4 additions & 4 deletions src/app/core/lineshape.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ thin.core.LineShape.prototype.update = function(attrs) {

this.calculateDirection(y1, y2);

this.setLeft(Math.min(x1, x2) + this.getParentTransLateX());
this.setTop(Math.min(y1, y2) + this.getParentTransLateY());
this.setWidth(Math.abs(x1 - x2));
this.setHeight(Math.abs(y1 - y2));
this.setLeft_(Math.min(x1, x2) + this.getParentTransLateX());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

プライベートメソッドは極力使いたくないし、理由がわからん。インスタンス変数だけ更新したいということだろうけど。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最初は インスタンス変数だけ更新しようとしていました。けれども、そもそもの setter の役割が果たせていない気がして private メソッドに分割したのです。

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

まあ、今回のところはいいでしょう。コメントは書いておきたいけど、1.0 で改善するしいいかな。

this.setTop_(Math.min(y1, y2) + this.getParentTransLateY());
this.setWidth_(Math.abs(x1 - x2));
this.setHeight_(Math.abs(y1 - y2));
}

};