feat: 优化代码

pull/105/head
kunfei 5 years ago
parent 04cf102be9
commit 51b1e48169
  1. 33
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt

@ -477,16 +477,8 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
* 计算拖拽点对应的拖拽脚 * 计算拖拽点对应的拖拽脚
*/ */
private fun calcCornerXY(x: Float, y: Float) { private fun calcCornerXY(x: Float, y: Float) {
mCornerX = if (x <= viewWidth / 2.0) { mCornerX = if (x <= viewWidth / 2.0) 0 else viewWidth
0 mCornerY = if (y <= viewHeight / 2.0) 0 else viewHeight
} else {
viewWidth
}
mCornerY = if (y <= viewHeight / 2.0) {
0
} else {
viewHeight
}
mIsRT_LB = (mCornerX == 0 && mCornerY == viewHeight) mIsRT_LB = (mCornerX == 0 && mCornerY == viewHeight)
|| (mCornerX == viewWidth && mCornerY == 0) || (mCornerX == viewWidth && mCornerY == 0)
} }
@ -499,10 +491,9 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
mBezierControl1.y = mCornerY.toFloat() mBezierControl1.y = mCornerY.toFloat()
mBezierControl2.x = mCornerX.toFloat() mBezierControl2.x = mCornerX.toFloat()
val f4 = mCornerY - mMiddleY val f4 = mCornerY - mMiddleY
if (f4 == 0f) { mBezierControl2.y = if (f4 == 0f) {
mBezierControl2.y = mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f
} else { } else {
mBezierControl2.y =
mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY)
} }
mBezierStart1.x = mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2 mBezierStart1.x = mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2
@ -524,11 +515,9 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
mBezierControl1.y = mCornerY.toFloat() mBezierControl1.y = mCornerY.toFloat()
mBezierControl2.x = mCornerX.toFloat() mBezierControl2.x = mCornerX.toFloat()
val f5 = mCornerY - mMiddleY val f5 = mCornerY - mMiddleY
if (f5 == 0f) { mBezierControl2.y = if (f5 == 0f) {
mBezierControl2.y =
mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f
} else { } else {
mBezierControl2.y =
mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY)
} }
mBezierStart1.x = (mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2) mBezierStart1.x = (mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2)
@ -537,14 +526,10 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi
mBezierStart2.x = mCornerX.toFloat() mBezierStart2.x = mCornerX.toFloat()
mBezierStart2.y = mBezierControl2.y - (mCornerY - mBezierControl2.y) / 2 mBezierStart2.y = mBezierControl2.y - (mCornerY - mBezierControl2.y) / 2
mTouchToCornerDis = hypot(touchX - mCornerX, touchY - mCornerY) mTouchToCornerDis = hypot(touchX - mCornerX, touchY - mCornerY)
mBezierEnd1 = getCross( mBezierEnd1 =
PointF(touchX, touchY), mBezierControl1, mBezierStart1, getCross(PointF(touchX, touchY), mBezierControl1, mBezierStart1, mBezierStart2)
mBezierStart2 mBezierEnd2 =
) getCross(PointF(touchX, touchY), mBezierControl2, mBezierStart1, mBezierStart2)
mBezierEnd2 = getCross(
PointF(touchX, touchY), mBezierControl2, mBezierStart1,
mBezierStart2
)
mBezierVertex1.x = (mBezierStart1.x + 2 * mBezierControl1.x + mBezierEnd1.x) / 4 mBezierVertex1.x = (mBezierStart1.x + 2 * mBezierControl1.x + mBezierEnd1.x) / 4
mBezierVertex1.y = (2 * mBezierControl1.y + mBezierStart1.y + mBezierEnd1.y) / 4 mBezierVertex1.y = (2 * mBezierControl1.y + mBezierStart1.y + mBezierEnd1.y) / 4
mBezierVertex2.x = (mBezierStart2.x + 2 * mBezierControl2.x + mBezierEnd2.x) / 4 mBezierVertex2.x = (mBezierStart2.x + 2 * mBezierControl2.x + mBezierEnd2.x) / 4

Loading…
Cancel
Save