diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2016-08-19 17:51:13 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2016-08-22 11:14:43 +0900 |
commit | 8a5c2586dc4f6854f8155331aad1c3fb2d54462f (patch) | |
tree | dfafafd8345b7ec6b87f81e295ed09d90f2f0dd6 /starmath | |
parent | 264466bd604d7613aa0a5e4b34c149ad66414580 (diff) |
starmath: Do SmCursor::MoveTo() more simply
... without unnecessary copy and re-calculation of squared distances.
Change-Id: I2900f8ef690cae750be036dcb3c4270c82286a4c
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/cursor.hxx | 2 | ||||
-rw-r--r-- | starmath/source/cursor.cxx | 14 |
2 files changed, 7 insertions, 9 deletions
diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx index 9fd913969185..8eac80689773 100644 --- a/starmath/inc/cursor.hxx +++ b/starmath/inc/cursor.hxx @@ -107,7 +107,7 @@ public: void Move(OutputDevice* pDev, SmMovementDirection direction, bool bMoveAnchor = true); /** Move to the caret position closet to a given point */ - void MoveTo(OutputDevice* pDev, Point pos, bool bMoveAnchor); + void MoveTo(OutputDevice* pDev, const Point& pos, bool bMoveAnchor); /** Delete the current selection or do nothing */ void Delete(); diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx index 35a06b700cda..a5a933edab9f 100644 --- a/starmath/source/cursor.cxx +++ b/starmath/source/cursor.cxx @@ -77,9 +77,8 @@ void SmCursor::Move(OutputDevice* pDev, SmMovementDirection direction, bool bMov } } -void SmCursor::MoveTo(OutputDevice* pDev, Point pos, bool bMoveAnchor){ - SmCaretLine best_line, //Best line found so far, when iterating - curr_line; //Current line, when iterating +void SmCursor::MoveTo(OutputDevice* pDev, const Point& pos, bool bMoveAnchor) +{ SmCaretPosGraphEntry* NewPos = nullptr; long dp_sq = 0, //Distance to current line squared dbp_sq = 1; //Distance to best line squared @@ -87,19 +86,18 @@ void SmCursor::MoveTo(OutputDevice* pDev, Point pos, bool bMoveAnchor){ { OSL_ENSURE(pEntry->CaretPos.IsValid(), "The caret position graph may not have invalid positions!"); //Compute current line - curr_line = SmCaretPos2LineVisitor(pDev, pEntry->CaretPos).GetResult(); + SmCaretLine curr_line = SmCaretPos2LineVisitor(pDev, pEntry->CaretPos).GetResult(); + //Compute squared distance to current line + dp_sq = curr_line.SquaredDistanceX(pos) + curr_line.SquaredDistanceY(pos); //If we have a position compare to it if(NewPos){ - //Compute squared distance to current line - dp_sq = curr_line.SquaredDistanceX(pos) + curr_line.SquaredDistanceY(pos); //If best line is closer, reject current line if(dbp_sq <= dp_sq) continue; } //Accept current position as the best - best_line = curr_line; NewPos = pEntry.get(); //Update distance to best line - dbp_sq = best_line.SquaredDistanceX(pos) + best_line.SquaredDistanceY(pos); + dbp_sq = dp_sq; } if(NewPos){ mpPosition = NewPos; |