triangle_unittest.cc 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stddef.h>
  5. #include "base/cxx17_backports.h"
  6. #include "build/build_config.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #include "ui/gfx/geometry/point_f.h"
  9. #include "ui/gfx/geometry/triangle_f.h"
  10. namespace gfx {
  11. namespace {
  12. constexpr PointF kPointA(1, 1);
  13. constexpr PointF kPointB(10, 1);
  14. constexpr PointF kPointC(1, 10);
  15. } // namespace
  16. TEST(TriangleTest, PointIsInTriangleInside) {
  17. PointF p(2, 2);
  18. EXPECT_TRUE(PointIsInTriangle(p, kPointA, kPointB, kPointC));
  19. }
  20. TEST(TriangleTest, PointIsInTriangleOutside) {
  21. PointF o(0, 0);
  22. EXPECT_FALSE(PointIsInTriangle(o, kPointA, kPointB, kPointC));
  23. }
  24. TEST(TriangleTest, PointIsInTriangleEdge) {
  25. PointF e(1, 3);
  26. EXPECT_TRUE(PointIsInTriangle(e, kPointA, kPointB, kPointC));
  27. }
  28. TEST(TriangleTest, PointIsInTriangleVertex) {
  29. EXPECT_TRUE(PointIsInTriangle(kPointA, kPointA, kPointB, kPointC));
  30. }
  31. } // namespace gfx