-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): node => rotate+正常模式resize(#1428) #1835
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export interface SimplePoint { | ||
x: number | ||
y: number | ||
} | ||
|
||
/** | ||
* 根据两个点获取中心点坐标 | ||
*/ | ||
export function getNewCenter(startPoint: SimplePoint, endPoint: SimplePoint) { | ||
const { x: x1, y: y1 } = startPoint | ||
const { x: x2, y: y2 } = endPoint | ||
const newCenter = { | ||
x: x1 + (x2 - x1) / 2, | ||
y: y1 + (y2 - y1) / 2, | ||
} | ||
return newCenter | ||
} | ||
|
||
/** | ||
* 旋转矩阵公式,可以获取某一个坐标旋转angle后的坐标 | ||
* @param p 当前坐标 | ||
* @param center 旋转中心 | ||
* @param angle 旋转角度(不是弧度) | ||
*/ | ||
export function calculatePointAfterRotateAngle( | ||
p: SimplePoint, | ||
center: SimplePoint, | ||
angle: number, | ||
) { | ||
const radian = angleToRadian(angle) | ||
const dx = p.x - center.x | ||
const dy = p.y - center.y | ||
const x = dx * Math.cos(radian) - dy * Math.sin(radian) + center.x | ||
const y = dx * Math.sin(radian) + dy * Math.cos(radian) + center.y | ||
return { | ||
x, | ||
y, | ||
} | ||
} | ||
|
||
/** | ||
* 角度转弧度 | ||
* @param angle 角度 | ||
*/ | ||
export function angleToRadian(angle: number) { | ||
return (angle * Math.PI) / 180 | ||
} | ||
|
||
/** | ||
* 弧度转角度 | ||
* @param radian 弧度 | ||
*/ | ||
export function radianToAngle(radian: number) { | ||
return (radian / Math.PI) * 180 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我可以接受这个类型定义,但其实我们内部是有一个 Position 的定义,用来表示坐标位置
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个SimplePoint的类型定义,在后续的pr中,我把它干掉,替换一下