SkPoint.h revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Copyright (C) 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Licensed under the Apache License, Version 2.0 (the "License"); 58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * you may not use this file except in compliance with the License. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * You may obtain a copy of the License at 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * http://www.apache.org/licenses/LICENSE-2.0 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Unless required by applicable law or agreed to in writing, software 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * distributed under the License is distributed on an "AS IS" BASIS, 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * See the License for the specific language governing permissions and 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * limitations under the License. 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkPoint_DEFINED 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkPoint_DEFINED 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMath.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScalar.h" 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \struct SkIPoint 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint holds two 32 bit integer coordinates 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkIPoint { 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int32_t fX, fY; 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the x and y values of the point. */ 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void set(int32_t x, int32_t y) { fX = x; fY = y; } 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Rotate the point clockwise, writing the new point into dst 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com It is legal for dst == this 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rotateCW(SkIPoint* dst) const; 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Rotate the point clockwise, writing the new point back into the point 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rotateCW() { this->rotateCW(this); } 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Rotate the point counter-clockwise, writing the new point into dst. 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com It is legal for dst == this 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rotateCCW(SkIPoint* dst) const; 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Rotate the point counter-clockwise, writing the new point back into 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the point 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rotateCCW() { this->rotateCCW(this); } 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Negate the X and Y coordinates of the point. 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void negate() { fX = -fX; fY = -fY; } 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new point whose X and Y coordinates are the negative of the 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com original point's 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint operator-() const { 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint neg; 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com neg.fX = -fX; 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com neg.fY = -fY; 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return neg; 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add v's coordinates to this point's */ 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void operator+=(const SkIPoint& v) { 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fX += v.fX; 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fY += v.fY; 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Subtract v's coordinates from this point's */ 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void operator-=(const SkIPoint& v) { 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fX -= v.fX; 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fY -= v.fY; 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the point's coordinates equal (x,y) */ 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool equals(int32_t x, int32_t y) const { 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fX == x && fY == y; 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend bool operator==(const SkIPoint& a, const SkIPoint& b) { 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return a.fX == b.fX && a.fY == b.fY; 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend bool operator!=(const SkIPoint& a, const SkIPoint& b) { 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return a.fX != b.fX || a.fY != b.fY; 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns a new point whose coordinates are the difference between 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a and b (i.e. a - b) 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend SkIPoint operator-(const SkIPoint& a, const SkIPoint& b) { 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint v; 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v.set(a.fX - b.fX, a.fY - b.fY); 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return v; 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns a new point whose coordinates are the sum of a and b (a + b) 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend SkIPoint operator+(const SkIPoint& a, const SkIPoint& b) { 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint v; 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v.set(a.fX + b.fX, a.fY + b.fY); 1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return v; 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the dot product of a and b, treating them as 2D vectors 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static int32_t DotProduct(const SkIPoint& a, const SkIPoint& b) { 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return a.fX * b.fX + a.fY * b.fY; 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the cross product of a and b, treating them as 2D vectors 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static int32_t CrossProduct(const SkIPoint& a, const SkIPoint& b) { 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return a.fX * b.fY - a.fY * b.fX; 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkPoint { 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fX, fY; 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the point's X and Y coordinates */ 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void set(SkScalar x, SkScalar y) { fX = x; fY = y; } 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the point's X and Y coordinates by automatically promoting (x,y) to 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar values. 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void iset(int32_t x, int32_t y) { 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fX = SkIntToScalar(x); 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fY = SkIntToScalar(y); 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the point's X and Y coordinates by automatically promoting p's 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com coordinates to SkScalar values. 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void iset(const SkIPoint& p) { 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fX = SkIntToScalar(p.fX); 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fY = SkIntToScalar(p.fY); 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the euclidian distance from (0,0) to the point 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar length() const { return SkPoint::Length(fX, fY); } 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the point (vector) to be unit-length in the same direction as it 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com currently is, and return its old length. If the old length is 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com degenerately small (nearly zero), do nothing and return false, otherwise 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true. 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool normalize(); 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the point (vector) to be unit-length in the same direction as the 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com x,y params. If the vector (x,y) has a degenerate length (i.e. nearly 0) 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com then return false and do nothing, otherwise return true. 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setNormalize(SkScalar x, SkScalar y); 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Scale the point (vector) to have the specified length, and return that 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com length. If the original length is degenerately small (nearly zero), 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do nothing and return false, otherwise return true. 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setLength(SkScalar length); 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the point (vector) to have the specified length in the same 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com direction as (x,y). If the vector (x,y) has a degenerate length 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (i.e. nearly 0) then return false and do nothing, otherwise return true. 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setLength(SkScalar x, SkScalar y, SkScalar length); 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Scale the point's coordinates by scale, writing the answer into dst. 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com It is legal for dst == this. 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void scale(SkScalar scale, SkPoint* dst) const; 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Scale the point's coordinates by scale, writing the answer back into 1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the point. 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void scale(SkScalar scale) { this->scale(scale, this); } 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Rotate the point clockwise by 90 degrees, writing the answer into dst. 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com It is legal for dst == this. 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rotateCW(SkPoint* dst) const; 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Rotate the point clockwise by 90 degrees, writing the answer back into 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the point. 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rotateCW() { this->rotateCW(this); } 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Rotate the point counter-clockwise by 90 degrees, writing the answer 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com into dst. It is legal for dst == this. 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rotateCCW(SkPoint* dst) const; 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Rotate the point counter-clockwise by 90 degrees, writing the answer 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com back into the point. 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rotateCCW() { this->rotateCCW(this); } 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Negate the point's coordinates 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void negate() { 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fX = -fX; 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fY = -fY; 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns a new point whose coordinates are the negative of the point's 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint operator-() const { 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint neg; 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com neg.fX = -fX; 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com neg.fY = -fY; 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return neg; 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add v's coordinates to the point's 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void operator+=(const SkPoint& v) { 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fX += v.fX; 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fY += v.fY; 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Subtract v's coordinates from the point's 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void operator-=(const SkPoint& v) { 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fX -= v.fX; 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fY -= v.fY; 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the point's coordinates equal (x,y) 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool equals(SkScalar x, SkScalar y) const { return fX == x && fY == y; } 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend bool operator==(const SkPoint& a, const SkPoint& b) { 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return a.fX == b.fX && a.fY == b.fY; 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend bool operator!=(const SkPoint& a, const SkPoint& b) { 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return a.fX != b.fX || a.fY != b.fY; 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns a new point whose coordinates are the difference between 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com a's and b's (a - b) 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend SkPoint operator-(const SkPoint& a, const SkPoint& b) { 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint v; 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v.set(a.fX - b.fX, a.fY - b.fY); 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return v; 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns a new point whose coordinates are the sum of a's and b's (a + b) 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend SkPoint operator+(const SkPoint& a, const SkPoint& b) { 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint v; 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com v.set(a.fX + b.fX, a.fY + b.fY); 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return v; 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the euclidian distance from (0,0) to (x,y) 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkScalar Length(SkScalar x, SkScalar y); 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the euclidian distance between a and b 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkScalar Distance(const SkPoint& a, const SkPoint& b) { 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return Length(a.fX - b.fX, a.fY - b.fY); 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the dot product of a and b, treating them as 2D vectors 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkScalar DotProduct(const SkPoint& a, const SkPoint& b) { 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkScalarMul(a.fX, b.fX) + SkScalarMul(a.fY, b.fY); 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the cross product of a and b, treating them as 2D vectors 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkScalar CrossProduct(const SkPoint& a, const SkPoint& b) { 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkScalarMul(a.fX, b.fY) - SkScalarMul(a.fY, b.fX); 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comtypedef SkPoint SkVector; 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 289