caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #include "SkPathOpsLine.h" |
| 8 | |
| 9 | SkDLine SkDLine::subDivide(double t1, double t2) const { |
| 10 | SkDVector delta = tangent(); |
| 11 | SkDLine dst = {{{ |
| 12 | fPts[0].fX - t1 * delta.fX, fPts[0].fY - t1 * delta.fY}, { |
| 13 | fPts[0].fX - t2 * delta.fX, fPts[0].fY - t2 * delta.fY}}}; |
| 14 | return dst; |
| 15 | } |
| 16 | |
| 17 | // may have this below somewhere else already: |
| 18 | // copying here because I thought it was clever |
| 19 | |
| 20 | // Copyright 2001, softSurfer (www.softsurfer.com) |
| 21 | // This code may be freely used and modified for any purpose |
| 22 | // providing that this copyright notice is included with it. |
| 23 | // SoftSurfer makes no warranty for this code, and cannot be held |
| 24 | // liable for any real or imagined damage resulting from its use. |
| 25 | // Users of this code must verify correctness for their application. |
| 26 | |
| 27 | // Assume that a class is already given for the object: |
| 28 | // Point with coordinates {float x, y;} |
| 29 | //=================================================================== |
| 30 | |
| 31 | // isLeft(): tests if a point is Left|On|Right of an infinite line. |
| 32 | // Input: three points P0, P1, and P2 |
| 33 | // Return: >0 for P2 left of the line through P0 and P1 |
| 34 | // =0 for P2 on the line |
| 35 | // <0 for P2 right of the line |
| 36 | // See: the January 2001 Algorithm on Area of Triangles |
| 37 | // return (float) ((P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y)); |
| 38 | double SkDLine::isLeft(const SkDPoint& pt) const { |
| 39 | SkDVector p0 = fPts[1] - fPts[0]; |
| 40 | SkDVector p2 = pt - fPts[0]; |
| 41 | return p0.cross(p2); |
| 42 | } |
| 43 | |
| 44 | SkDPoint SkDLine::xyAtT(double t) const { |
| 45 | double one_t = 1 - t; |
| 46 | SkDPoint result = { one_t * fPts[0].fX + t * fPts[1].fX, one_t * fPts[0].fY + t * fPts[1].fY }; |
| 47 | return result; |
| 48 | } |