本文整理汇总了C++中SkVector::scale方法的典型用法代码示例。如果您正苦于以下问题:C++ SkVector::scale方法的具体用法?C++ SkVector::scale怎么用?C++ SkVector::scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkVector
的用法示例。
在下文中一共展示了SkVector::scale方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pts_to_unit_matrix
static void pts_to_unit_matrix(const SkPoint pts[2], SkMatrix* matrix) {
SkVector vec = pts[1] - pts[0];
SkScalar mag = vec.length();
SkScalar inv = mag ? SkScalarInvert(mag) : 0;
vec.scale(inv);
matrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY);
matrix->postTranslate(-pts[0].fX, -pts[0].fY);
matrix->postScale(inv, inv);
}
示例2: unitToPointsMatrix
static void unitToPointsMatrix(const SkPoint pts[2], SkMatrix* matrix) {
SkVector vec = pts[1] - pts[0];
SkScalar mag = vec.length();
SkScalar inv = mag ? SkScalarInvert(mag) : 0;
vec.scale(inv);
matrix->setSinCos(vec.fY, vec.fX);
matrix->preTranslate(pts[0].fX, pts[0].fY);
matrix->preScale(mag, mag);
}
示例3: toUnitMatrix
static void toUnitMatrix(const SkPoint pts[2], SkMatrix* matrix) {
SkVector vec = pts[1] - pts[0];
const float mag = vec.length();
const float inv = mag ? 1.0f / mag : 0;
vec.scale(inv);
matrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY);
matrix->postTranslate(-pts[0].fX, -pts[0].fY);
matrix->postScale(inv, inv);
}
示例4: pts_to_unit_matrix
static SkMatrix pts_to_unit_matrix(const SkPoint pts[2]) {
SkVector vec = pts[1] - pts[0];
SkScalar mag = vec.length();
SkScalar inv = mag ? SkScalarInvert(mag) : 0;
vec.scale(inv);
SkMatrix matrix;
matrix.setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY);
matrix.postTranslate(-pts[0].fX, -pts[0].fY);
matrix.postScale(inv, inv);
return matrix;
}
示例5: align_to_x_axis
// calculates the rotation needed to aligned pts to the x axis with pts[0] < pts[1]
// Stores the rotation matrix in rotMatrix, and the mapped points in ptsRot
static void align_to_x_axis(const SkPoint pts[2], SkMatrix* rotMatrix, SkPoint ptsRot[2] = NULL) {
SkVector vec = pts[1] - pts[0];
SkScalar mag = vec.length();
SkScalar inv = mag ? SkScalarInvert(mag) : 0;
vec.scale(inv);
rotMatrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY);
if (ptsRot) {
rotMatrix->mapPoints(ptsRot, pts, 2);
// correction for numerical issues if map doesn't make ptsRot exactly horizontal
ptsRot[1].fY = pts[0].fY;
}
}
示例6: BluntJoiner
static void BluntJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnitNormal,
const SkPoint& pivot, const SkVector& afterUnitNormal,
SkScalar radius, SkScalar invMiterLimit, bool, bool)
{
SkVector after;
afterUnitNormal.scale(radius, &after);
if (!is_clockwise(beforeUnitNormal, afterUnitNormal))
{
SkTSwap<SkPath*>(outer, inner);
after.negate();
}
outer->lineTo(pivot.fX + after.fX, pivot.fY + after.fY);
HandleInnerJoin(inner, pivot, after);
}
示例7: calc_dash_scaling
static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale,
const SkMatrix& viewMatrix, const SkPoint pts[2]) {
SkVector vecSrc = pts[1] - pts[0];
SkScalar magSrc = vecSrc.length();
SkScalar invSrc = magSrc ? SkScalarInvert(magSrc) : 0;
vecSrc.scale(invSrc);
SkVector vecSrcPerp;
vecSrc.rotateCW(&vecSrcPerp);
viewMatrix.mapVectors(&vecSrc, 1);
viewMatrix.mapVectors(&vecSrcPerp, 1);
// parallelScale tells how much to scale along the line parallel to the dash line
// perpScale tells how much to scale in the direction perpendicular to the dash line
*parallelScale = vecSrc.length();
*perpScale = vecSrcPerp.length();
}
示例8: RoundJoiner
static void RoundJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnitNormal,
const SkPoint& pivot, const SkVector& afterUnitNormal,
SkScalar radius, SkScalar invMiterLimit, bool, bool)
{
SkScalar dotProd = SkPoint::DotProduct(beforeUnitNormal, afterUnitNormal);
AngleType angleType = Dot2AngleType(dotProd);
if (angleType == kNearlyLine_AngleType)
return;
SkVector before = beforeUnitNormal;
SkVector after = afterUnitNormal;
SkRotationDirection dir = kCW_SkRotationDirection;
if (!is_clockwise(before, after))
{
SkTSwap<SkPath*>(outer, inner);
before.negate();
after.negate();
dir = kCCW_SkRotationDirection;
}
SkPoint pts[kSkBuildQuadArcStorage];
SkMatrix matrix;
matrix.setScale(radius, radius);
matrix.postTranslate(pivot.fX, pivot.fY);
int count = SkBuildQuadArc(before, after, dir, &matrix, pts);
SkASSERT((count & 1) == 1);
if (count > 1)
{
for (int i = 1; i < count; i += 2)
outer->quadTo(pts[i].fX, pts[i].fY, pts[i+1].fX, pts[i+1].fY);
after.scale(radius);
HandleInnerJoin(inner, pivot, after);
}
}
示例9: asPoints
// Currently asPoints is more restrictive then it needs to be. In the future
// we need to:
// allow kRound_Cap capping (could allow rotations in the matrix with this)
// allow paths to be returned
bool SkDashPathEffect::asPoints(PointData* results,
const SkPath& src,
const SkStrokeRec& rec,
const SkMatrix& matrix,
const SkRect* cullRect) const {
// width < 0 -> fill && width == 0 -> hairline so requiring width > 0 rules both out
if (fInitialDashLength < 0 || 0 >= rec.getWidth()) {
return false;
}
// TODO: this next test could be eased up. We could allow any number of
// intervals as long as all the ons match and all the offs match.
// Additionally, they do not necessarily need to be integers.
// We cannot allow arbitrary intervals since we want the returned points
// to be uniformly sized.
if (fCount != 2 ||
!SkScalarNearlyEqual(fIntervals[0], fIntervals[1]) ||
!SkScalarIsInt(fIntervals[0]) ||
!SkScalarIsInt(fIntervals[1])) {
return false;
}
SkPoint pts[2];
if (!src.isLine(pts)) {
return false;
}
// TODO: this test could be eased up to allow circles
if (SkPaint::kButt_Cap != rec.getCap()) {
return false;
}
// TODO: this test could be eased up for circles. Rotations could be allowed.
if (!matrix.rectStaysRect()) {
return false;
}
// See if the line can be limited to something plausible.
if (!cull_line(pts, rec, matrix, cullRect, fIntervalLength)) {
return false;
}
SkScalar length = SkPoint::Distance(pts[1], pts[0]);
SkVector tangent = pts[1] - pts[0];
if (tangent.isZero()) {
return false;
}
tangent.scale(SkScalarInvert(length));
// TODO: make this test for horizontal & vertical lines more robust
bool isXAxis = true;
if (SkScalarNearlyEqual(SK_Scalar1, tangent.fX) ||
SkScalarNearlyEqual(-SK_Scalar1, tangent.fX)) {
results->fSize.set(SkScalarHalf(fIntervals[0]), SkScalarHalf(rec.getWidth()));
} else if (SkScalarNearlyEqual(SK_Scalar1, tangent.fY) ||
SkScalarNearlyEqual(-SK_Scalar1, tangent.fY)) {
results->fSize.set(SkScalarHalf(rec.getWidth()), SkScalarHalf(fIntervals[0]));
isXAxis = false;
} else if (SkPaint::kRound_Cap != rec.getCap()) {
// Angled lines don't have axis-aligned boxes.
return false;
}
if (results) {
results->fFlags = 0;
SkScalar clampedInitialDashLength = SkMinScalar(length, fInitialDashLength);
if (SkPaint::kRound_Cap == rec.getCap()) {
results->fFlags |= PointData::kCircles_PointFlag;
}
results->fNumPoints = 0;
SkScalar len2 = length;
if (clampedInitialDashLength > 0 || 0 == fInitialDashIndex) {
SkASSERT(len2 >= clampedInitialDashLength);
if (0 == fInitialDashIndex) {
if (clampedInitialDashLength > 0) {
if (clampedInitialDashLength >= fIntervals[0]) {
++results->fNumPoints; // partial first dash
}
len2 -= clampedInitialDashLength;
}
len2 -= fIntervals[1]; // also skip first space
if (len2 < 0) {
len2 = 0;
}
} else {
len2 -= clampedInitialDashLength; // skip initial partial empty
}
}
int numMidPoints = SkScalarFloorToInt(len2 / fIntervalLength);
results->fNumPoints += numMidPoints;
len2 -= numMidPoints * fIntervalLength;
//.........这里部分代码省略.........
示例10: MiterJoiner
static void MiterJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnitNormal,
const SkPoint& pivot, const SkVector& afterUnitNormal,
SkScalar radius, SkScalar invMiterLimit,
bool prevIsLine, bool currIsLine)
{
// negate the dot since we're using normals instead of tangents
SkScalar dotProd = SkPoint::DotProduct(beforeUnitNormal, afterUnitNormal);
AngleType angleType = Dot2AngleType(dotProd);
SkVector before = beforeUnitNormal;
SkVector after = afterUnitNormal;
SkVector mid;
SkScalar sinHalfAngle;
bool ccw;
if (angleType == kNearlyLine_AngleType)
return;
if (angleType == kNearly180_AngleType)
{
currIsLine = false;
goto DO_BLUNT;
}
ccw = !is_clockwise(before, after);
if (ccw)
{
SkTSwap<SkPath*>(outer, inner);
before.negate();
after.negate();
}
/* Before we enter the world of square-roots and divides,
check if we're trying to join an upright right angle
(common case for stroking rectangles). If so, special case
that (for speed an accuracy).
Note: we only need to check one normal if dot==0
*/
if (0 == dotProd && invMiterLimit <= kOneOverSqrt2)
{
mid.set(SkScalarMul(before.fX + after.fX, radius),
SkScalarMul(before.fY + after.fY, radius));
goto DO_MITER;
}
/* midLength = radius / sinHalfAngle
if (midLength > miterLimit * radius) abort
if (radius / sinHalf > miterLimit * radius) abort
if (1 / sinHalf > miterLimit) abort
if (1 / miterLimit > sinHalf) abort
My dotProd is opposite sign, since it is built from normals and not tangents
hence 1 + dot instead of 1 - dot in the formula
*/
sinHalfAngle = SkScalarSqrt(SkScalarHalf(SK_Scalar1 + dotProd));
if (sinHalfAngle < invMiterLimit)
{
currIsLine = false;
goto DO_BLUNT;
}
// choose the most accurate way to form the initial mid-vector
if (angleType == kSharp_AngleType)
{
mid.set(after.fY - before.fY, before.fX - after.fX);
if (ccw)
mid.negate();
}
else
mid.set(before.fX + after.fX, before.fY + after.fY);
mid.setLength(SkScalarDiv(radius, sinHalfAngle));
DO_MITER:
if (prevIsLine)
outer->setLastPt(pivot.fX + mid.fX, pivot.fY + mid.fY);
else
outer->lineTo(pivot.fX + mid.fX, pivot.fY + mid.fY);
DO_BLUNT:
after.scale(radius);
if (!currIsLine)
outer->lineTo(pivot.fX + after.fX, pivot.fY + after.fY);
HandleInnerJoin(inner, pivot, after);
}