1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2020 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "include/utils/SkRandom.h"
9cb93a386Sopenharmony_ci#include "src/core/SkGeometry.h"
10cb93a386Sopenharmony_ci#include "src/gpu/GrVx.h"
11cb93a386Sopenharmony_ci#include "tests/Test.h"
12cb93a386Sopenharmony_ci#include <limits>
13cb93a386Sopenharmony_ci#include <numeric>
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ciusing namespace grvx;
16cb93a386Sopenharmony_ciusing skvx::bit_pun;
17cb93a386Sopenharmony_ci
18cb93a386Sopenharmony_ciDEF_TEST(grvx_cross_dot, r) {
19cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::cross({0,1}, {0,1}) == 0);
20cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::cross({1,0}, {1,0}) == 0);
21cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::cross({1,1}, {1,1}) == 0);
22cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::cross({1,1}, {1,-1}) == -2);
23cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::cross({1,1}, {-1,1}) == 2);
24cb93a386Sopenharmony_ci
25cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::dot({0,1}, {1,0}) == 0);
26cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::dot({1,0}, {0,1}) == 0);
27cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::dot({1,1}, {1,-1}) == 0);
28cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::dot({1,1}, {1,1}) == 2);
29cb93a386Sopenharmony_ci    REPORTER_ASSERT(r, grvx::dot({1,1}, {-1,-1}) == -2);
30cb93a386Sopenharmony_ci
31cb93a386Sopenharmony_ci    SkRandom rand;
32cb93a386Sopenharmony_ci    for (int i = 0; i < 100; ++i) {
33cb93a386Sopenharmony_ci        float a=rand.nextRangeF(-1,1), b=rand.nextRangeF(-1,1), c=rand.nextRangeF(-1,1),
34cb93a386Sopenharmony_ci              d=rand.nextRangeF(-1,1);
35cb93a386Sopenharmony_ci        constexpr static float kTolerance = 1.f / (1 << 20);
36cb93a386Sopenharmony_ci        REPORTER_ASSERT(r, SkScalarNearlyEqual(
37cb93a386Sopenharmony_ci                grvx::cross({a,b}, {c,d}), SkPoint::CrossProduct({a,b}, {c,d}), kTolerance));
38cb93a386Sopenharmony_ci        REPORTER_ASSERT(r, SkScalarNearlyEqual(
39cb93a386Sopenharmony_ci                grvx::dot({a,b}, {c,d}), SkPoint::DotProduct({a,b}, {c,d}), kTolerance));
40cb93a386Sopenharmony_ci    }
41cb93a386Sopenharmony_ci}
42