Commit 60808884 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Use consistently computed lengths when finding relevant contour

In CalculatePointAndNormalOnPath, compute the accumulated length of the
contours and compare against the passed in (now unmodified) |length|, to
increase the chances of comparing similarly computed length with each
other. |length| is often, directly or indirectly, derived from the
computed length of the Path (i.e using Path::length().)

Bug: 845375
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Ibda61dd29921f41e0b294edde31ddb21ebbefd08
Reviewed-on: https://chromium-review.googlesource.com/1069071
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarFlorin Malita <fmalita@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561032}
parent 524e60fb
......@@ -1828,6 +1828,7 @@ jumbo_source_set("blink_platform_unittests_sources") {
"graphics/paint/paint_record_builder_test.cc",
"graphics/paint/property_tree_state_test.cc",
"graphics/paint_invalidation_reason_test.cc",
"graphics/path_test.cc",
"graphics/placeholder_image_test.cc",
"graphics/skia/skia_utils_test.cc",
"graphics/static_bitmap_image_test.cc",
......
......@@ -198,19 +198,19 @@ FloatPoint Path::PointAtLength(float length) const {
return point;
}
static bool CalculatePointAndNormalOnPath(
SkPathMeasure& measure,
SkScalar length,
FloatPoint& point,
float& normal_angle,
SkScalar* accumulated_length = nullptr) {
static bool CalculatePointAndNormalOnPath(SkPathMeasure& measure,
SkScalar& contour_start,
SkScalar length,
FloatPoint& point,
float& normal_angle) {
do {
SkScalar contour_length = measure.getLength();
if (length <= contour_length) {
SkScalar contour_end = contour_start + measure.getLength();
if (length <= contour_end) {
SkVector tangent;
SkPoint position;
if (measure.getPosTan(length, &position, &tangent)) {
SkScalar pos_in_contour = length - contour_start;
if (measure.getPosTan(pos_in_contour, &position, &tangent)) {
normal_angle =
rad2deg(SkScalarToFloat(SkScalarATan2(tangent.fY, tangent.fX)));
point = FloatPoint(SkScalarToFloat(position.fX),
......@@ -218,9 +218,7 @@ static bool CalculatePointAndNormalOnPath(
return true;
}
}
length -= contour_length;
if (accumulated_length)
*accumulated_length += contour_length;
contour_start = contour_end;
} while (measure.nextContour());
return false;
}
......@@ -229,8 +227,9 @@ void Path::PointAndNormalAtLength(float length,
FloatPoint& point,
float& normal) const {
SkPathMeasure measure(path_, false);
if (CalculatePointAndNormalOnPath(measure, WebCoreFloatToSkScalar(length),
point, normal))
SkScalar start = 0;
if (CalculatePointAndNormalOnPath(
measure, start, WebCoreFloatToSkScalar(length), point, normal))
return;
SkPoint position = path_.getPoint(0);
......@@ -253,12 +252,10 @@ void Path::PositionCalculator::PointAndNormalAtLength(float length,
// Reset path measurer to rewind (and restart from 0).
path_measure_.setPath(&path_, false);
accumulated_length_ = 0;
} else {
sk_length -= accumulated_length_;
}
if (CalculatePointAndNormalOnPath(path_measure_, sk_length, point,
normal_angle, &accumulated_length_))
if (CalculatePointAndNormalOnPath(path_measure_, accumulated_length_,
sk_length, point, normal_angle))
return;
}
......@@ -266,7 +263,6 @@ void Path::PositionCalculator::PointAndNormalAtLength(float length,
point =
FloatPoint(SkScalarToFloat(position.fX), SkScalarToFloat(position.fY));
normal_angle = 0;
return;
}
void Path::Clear() {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/graphics/path.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
TEST(PathTest, PointAtEndOfPath) {
Path path;
path.MoveTo(FloatPoint(70, -48));
path.AddBezierCurveTo(FloatPoint(70, -48), FloatPoint(136, 136),
FloatPoint(230, 166));
path.MoveTo(FloatPoint(230, 166));
path.AddBezierCurveTo(FloatPoint(324, 196), FloatPoint(472, 370),
FloatPoint(460, 470));
FloatPoint point;
float angle;
path.PointAndNormalAtLength(path.length(), point, angle);
EXPECT_EQ(point, FloatPoint(460, 470));
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment