OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 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 |
| 8 #include "SkPatchUtils.h" |
| 9 |
| 10 #include "SkGeometry.h" |
| 11 |
| 12 SkIPoint SkPatchUtils::GetLevelOfDetail(const SkPatch& patch, const SkMatrix* ma
trix) { |
| 13 |
| 14 SkPoint mapPts[12]; |
| 15 matrix->mapPoints(mapPts, patch.getControlPoints(), 12); |
| 16 |
| 17 // Approximate length of each cubic. |
| 18 SkPoint pts[4]; |
| 19 patch.getTopPoints(pts); |
| 20 matrix->mapPoints(pts, 4); |
| 21 int topLength = approx_arc_length(pts, 4); |
| 22 |
| 23 patch.getBottomPoints(pts); |
| 24 matrix->mapPoints(pts, 4); |
| 25 int bottomLength = approx_arc_length(pts, 4); |
| 26 |
| 27 patch.getLeftPoints(pts); |
| 28 matrix->mapPoints(pts, 4); |
| 29 int leftLength = approx_arc_length(pts, 4); |
| 30 |
| 31 patch.getRightPoints(pts); |
| 32 matrix->mapPoints(pts, 4); |
| 33 int rightLength = approx_arc_length(pts, 4); |
| 34 |
| 35 // Level of detail per axis, based on the larger side between top and bottom
or left and right |
| 36 int lodX = SkMaxScalar(topLength, bottomLength) / kPartitionSize; |
| 37 int lodY = SkMaxScalar(leftLength, rightLength) / kPartitionSize; |
| 38 |
| 39 return SkIPoint::Make(SkMax32(4, lodX), SkMax32(4, lodY)); |
| 40 } |
OLD | NEW |