本文整理汇总了C++中SkVector类的典型用法代码示例。如果您正苦于以下问题:C++ SkVector类的具体用法?C++ SkVector怎么用?C++ SkVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect_lines
static void intersect_lines(const SkPoint& ptA, const SkVector& normA,
const SkPoint& ptB, const SkVector& normB,
SkPoint* result) {
SkScalar lineAW = -normA.dot(ptA);
SkScalar lineBW = -normB.dot(ptB);
SkScalar wInv = SkScalarMul(normA.fX, normB.fY) -
SkScalarMul(normA.fY, normB.fX);
wInv = SkScalarInvert(wInv);
result->fX = SkScalarMul(normA.fY, lineBW) - SkScalarMul(lineAW, normB.fY);
result->fX = SkScalarMul(result->fX, wInv);
result->fY = SkScalarMul(lineAW, normB.fX) - SkScalarMul(normA.fX, lineBW);
result->fY = SkScalarMul(result->fY, wInv);
}
示例2: distanceToLineBetweenSqd
SkScalar SkPoint::distanceToLineBetweenSqd(const SkPoint& a,
const SkPoint& b,
Side* side) const {
SkVector u = b - a;
SkVector v = *this - a;
SkScalar uLengthSqd = u.lengthSqd();
SkScalar det = u.cross(v);
if (side) {
SkASSERT(-1 == SkPoint::kLeft_Side &&
0 == SkPoint::kOn_Side &&
1 == kRight_Side);
*side = (Side) SkScalarSignAsInt(det);
}
return SkScalarMulDiv(det, det, uLengthSqd);
}
示例3: SkScalarRoundToInt
bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!cropRectIsSet()) {
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkVector vec;
ctx.ctm().mapVectors(&vec, &fOffset, 1);
offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX);
offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY);
*result = src;
} else {
if (!this->filterInput(0, proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkIRect bounds;
if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) {
return false;
}
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
if (nullptr == device.get()) {
return false;
}
SkCanvas canvas(device);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft),
SkIntToScalar(srcOffset.fY - bounds.fTop));
SkVector vec;
ctx.ctm().mapVectors(&vec, &fOffset, 1);
canvas.drawBitmap(src, vec.x(), vec.y(), &paint);
*result = device->accessBitmap(false);
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
}
return true;
}
示例4: draw
void draw(SkCanvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } };
const SkPoint origin = {0, 0};
canvas->translate(30, 140);
for (auto point : points) {
paint.setStrokeWidth(1);
paint.setColor(SK_ColorBLACK);
canvas->drawLine(origin, point, paint);
SkVector normal;
normal.setNormalize(point.fX, point.fY);
normal *= 100;
paint.setStrokeWidth(10);
paint.setColor(0x3f4512bf);
canvas->drawLine(origin, normal, paint);
}
}
示例5: SkScalarCeil
bool SkEmbossMaskFilter::filterMask(SkMask* dst, const SkMask& src, const SkMatrix& matrix, SkIPoint* margin)
{
SkScalar radius = matrix.mapRadius(fBlurRadius);
if (!SkBlurMask::Blur(dst, src, radius, SkBlurMask::kInner_Style))
return false;
dst->fFormat = SkMask::k3D_Format;
if (margin)
margin->set(SkScalarCeil(radius), SkScalarCeil(radius));
if (src.fImage == NULL)
return true;
// create a larger buffer for the other two channels (should force fBlur to do this for us)
{
uint8_t* alphaPlane = dst->fImage;
size_t planeSize = dst->computeImageSize();
dst->fImage = SkMask::AllocImage(planeSize * 3);
memcpy(dst->fImage, alphaPlane, planeSize);
SkMask::FreeImage(alphaPlane);
}
// run the light direction through the matrix...
Light light = fLight;
matrix.mapVectors((SkVector*)(void*)light.fDirection, (SkVector*)(void*)fLight.fDirection, 1);
// now restore the length of the XY component
// cast to SkVector so we can call setLength (this double cast silences alias warnings)
SkVector* vec = (SkVector*)(void*)light.fDirection;
vec->setLength(light.fDirection[0],
light.fDirection[1],
SkPoint::Length(fLight.fDirection[0], fLight.fDirection[1]));
SkEmbossMask::Emboss(dst, light);
// restore original alpha
memcpy(dst->fImage, src.fImage, src.computeImageSize());
return true;
}
示例6: test_conic_tangents
static void test_conic_tangents(skiatest::Reporter* reporter) {
SkPoint pts[] = {
{ 10, 20}, {10, 20}, {20, 30},
{ 10, 20}, {15, 25}, {20, 30},
{ 10, 20}, {20, 30}, {20, 30}
};
int count = (int) SK_ARRAY_COUNT(pts) / 3;
for (int index = 0; index < count; ++index) {
SkConic conic(&pts[index * 3], 0.707f);
SkVector start = conic.evalTangentAt(0);
SkVector mid = conic.evalTangentAt(.5f);
SkVector end = conic.evalTangentAt(1);
REPORTER_ASSERT(reporter, start.fX && start.fY);
REPORTER_ASSERT(reporter, mid.fX && mid.fY);
REPORTER_ASSERT(reporter, end.fX && end.fY);
REPORTER_ASSERT(reporter, SkScalarNearlyZero(start.cross(mid)));
REPORTER_ASSERT(reporter, SkScalarNearlyZero(mid.cross(end)));
}
}
示例7: compute_intersection
// Compute the intersection 'p' between segments s0 and s1, if any.
// 's' is the parametric value for the intersection along 's0' & 't' is the same for 's1'.
// Returns false if there is no intersection.
static bool compute_intersection(const InsetSegment& s0, const InsetSegment& s1,
SkPoint* p, SkScalar* s, SkScalar* t) {
SkVector v0 = s0.fP1 - s0.fP0;
SkVector v1 = s1.fP1 - s1.fP0;
SkScalar perpDot = v0.cross(v1);
if (SkScalarNearlyZero(perpDot)) {
// segments are parallel
// check if endpoints are touching
if (s0.fP1.equalsWithinTolerance(s1.fP0)) {
*p = s0.fP1;
*s = SK_Scalar1;
*t = 0;
return true;
}
if (s1.fP1.equalsWithinTolerance(s0.fP0)) {
*p = s1.fP1;
*s = 0;
*t = SK_Scalar1;
return true;
}
return false;
}
SkVector d = s1.fP0 - s0.fP0;
SkScalar localS = d.cross(v1) / perpDot;
if (localS < 0 || localS > SK_Scalar1) {
return false;
}
SkScalar localT = d.cross(v0) / perpDot;
if (localT < 0 || localT > SK_Scalar1) {
return false;
}
v0 *= localS;
*p = s0.fP0 + v0;
*s = localS;
*t = localT;
return true;
}
示例8: SkASSERT
void GrAAConvexTessellator::computeBisectors() {
fBisectors.setCount(fNorms.count());
int prev = fBisectors.count() - 1;
for (int cur = 0; cur < fBisectors.count(); prev = cur, ++cur) {
fBisectors[cur] = fNorms[cur] + fNorms[prev];
if (!fBisectors[cur].normalize()) {
SkASSERT(SkPoint::kLeft_Side == fSide || SkPoint::kRight_Side == fSide);
fBisectors[cur].setOrthog(fNorms[cur], (SkPoint::Side)-fSide);
SkVector other;
other.setOrthog(fNorms[prev], fSide);
fBisectors[cur] += other;
SkAssertResult(fBisectors[cur].normalize());
} else {
fBisectors[cur].negate(); // make the bisector face in
}
SkASSERT(SkScalarNearlyEqual(1.0f, fBisectors[cur].length()));
}
}
示例9: mapSigma
bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
#if SK_SUPPORT_GPU
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect srcBounds, dstBounds;
if (!this->applyCropRect(this->mapContext(ctx), input, srcOffset, &dstBounds, &srcBounds)) {
return false;
}
if (!srcBounds.intersect(dstBounds)) {
return false;
}
GrTexture* source = input.getTexture();
SkVector sigma = mapSigma(fSigma, ctx.ctm());
offset->fX = dstBounds.fLeft;
offset->fY = dstBounds.fTop;
srcBounds.offset(-srcOffset);
dstBounds.offset(-srcOffset);
SkRect srcBoundsF(SkRect::Make(srcBounds));
auto constraint = GrTextureProvider::FromImageFilter(ctx.sizeConstraint());
SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(),
source,
false,
SkRect::Make(dstBounds),
&srcBoundsF,
sigma.x(),
sigma.y(),
constraint));
if (!tex) {
return false;
}
WrapTexture(tex, dstBounds.width(), dstBounds.height(), result);
return true;
#else
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
#endif
}
示例10: SkOffsetSegment
// Offset line segment p0-p1 'd0' and 'd1' units in the direction specified by 'side'
bool SkOffsetSegment(const SkPoint& p0, const SkPoint& p1, SkScalar d0, SkScalar d1,
int side, SkPoint* offset0, SkPoint* offset1) {
SkASSERT(side == -1 || side == 1);
SkVector perp = SkVector::Make(p0.fY - p1.fY, p1.fX - p0.fX);
if (SkScalarNearlyEqual(d0, d1)) {
// if distances are equal, can just outset by the perpendicular
perp.setLength(d0*side);
*offset0 = p0 + perp;
*offset1 = p1 + perp;
} else {
// Otherwise we need to compute the outer tangent.
// See: http://www.ambrsoft.com/TrigoCalc/Circles2/Circles2Tangent_.htm
if (d0 < d1) {
side = -side;
}
SkScalar dD = d0 - d1;
// if one circle is inside another, we can't compute an offset
if (dD*dD >= p0.distanceToSqd(p1)) {
return false;
}
SkPoint outerTangentIntersect = SkPoint::Make((p1.fX*d0 - p0.fX*d1) / dD,
(p1.fY*d0 - p0.fY*d1) / dD);
SkScalar d0sq = d0*d0;
SkVector dP = outerTangentIntersect - p0;
SkScalar dPlenSq = dP.lengthSqd();
SkScalar discrim = SkScalarSqrt(dPlenSq - d0sq);
offset0->fX = p0.fX + (d0sq*dP.fX - side*d0*dP.fY*discrim) / dPlenSq;
offset0->fY = p0.fY + (d0sq*dP.fY + side*d0*dP.fX*discrim) / dPlenSq;
SkScalar d1sq = d1*d1;
dP = outerTangentIntersect - p1;
dPlenSq = dP.lengthSqd();
discrim = SkScalarSqrt(dPlenSq - d1sq);
offset1->fX = p1.fX + (d1sq*dP.fX - side*d1*dP.fY*discrim) / dPlenSq;
offset1->fY = p1.fY + (d1sq*dP.fY + side*d1*dP.fX*discrim) / dPlenSq;
}
return true;
}
示例11: MakeImage
static sk_sp<SkImage> MakeImage(const SkVector& vec, SkColor color) {
const SkPoint start = SkPoint::Make(vec.y() * kSegLen / 2, vec.x() * kSegLen / 2);
const SkPoint end = SkPoint::Make(start.x() + vec.x() * (kSegLen - 1),
start.y() + vec.y() * (kSegLen - 1));
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kSegLen, kSegLen));
surface->getCanvas()->clear(SK_ColorTRANSPARENT);
SkPaint paint;
paint.setAntiAlias(true);
const SkRect border = SkRect::MakeIWH(kSegLen, kSegLen).makeInset(.5f, .5f);
paint.setColor(SK_ColorBLUE);
paint.setStyle(SkPaint::kStroke_Style);
surface->getCanvas()->drawRect(border, paint);
paint.setColor(SK_ColorBLACK);
surface->getCanvas()->drawLine(start.x(), start.y(), end.x(), end.y(), paint);
surface->getCanvas()->drawPoint(start.x(), start.y(), color);
surface->getCanvas()->drawPoint(end.x(), end.y(), color);
return surface->makeImageSnapshot();
}
示例12: compute_central_occluder
// Use the intersection of the corners' diagonals with their ellipses to shrink
// the bounding rect
SkRect compute_central_occluder(const SkRRect& rr) {
const SkRect r = rr.getBounds();
SkScalar newL = r.fLeft, newT = r.fTop, newR = r.fRight, newB = r.fBottom;
SkVector radii = rr.radii(SkRRect::kUpperLeft_Corner);
if (!radii.isZero()) {
SkPoint p = intersection(radii.fX, radii.fY);
newL = SkTMax(newL, r.fLeft + radii.fX - p.fX);
newT = SkTMax(newT, r.fTop + radii.fY - p.fY);
}
radii = rr.radii(SkRRect::kUpperRight_Corner);
if (!radii.isZero()) {
SkPoint p = intersection(radii.fX, radii.fY);
newR = SkTMin(newR, r.fRight + p.fX - radii.fX);
newT = SkTMax(newT, r.fTop + radii.fY - p.fY);
}
radii = rr.radii(SkRRect::kLowerRight_Corner);
if (!radii.isZero()) {
SkPoint p = intersection(radii.fX, radii.fY);
newR = SkTMin(newR, r.fRight + p.fX - radii.fX);
newB = SkTMin(newB, r.fBottom - radii.fY + p.fY);
}
radii = rr.radii(SkRRect::kLowerLeft_Corner);
if (!radii.isZero()) {
SkPoint p = intersection(radii.fX, radii.fY);
newL = SkTMax(newL, r.fLeft + radii.fX - p.fX);
newB = SkTMin(newB, r.fBottom - radii.fY + p.fY);
}
return SkRect::MakeLTRB(newL, newT, newR, newB);
}
示例13: 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);
}
}
示例14: 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();
}
示例15: SquareCapper
static void SquareCapper(SkPath* path, const SkPoint& pivot,
const SkVector& normal, const SkPoint& stop,
SkPath* otherPath)
{
SkVector parallel;
normal.rotateCW(¶llel);
if (otherPath)
{
path->setLastPt(pivot.fX + normal.fX + parallel.fX, pivot.fY + normal.fY + parallel.fY);
path->lineTo(pivot.fX - normal.fX + parallel.fX, pivot.fY - normal.fY + parallel.fY);
}
else
{
path->lineTo(pivot.fX + normal.fX + parallel.fX, pivot.fY + normal.fY + parallel.fY);
path->lineTo(pivot.fX - normal.fX + parallel.fX, pivot.fY - normal.fY + parallel.fY);
path->lineTo(stop.fX, stop.fY);
}
}