Lagrange
triangle_orientation_2d.h
1/*
2 * Copyright 2023 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ExactPredicates.h>
15#include <lagrange/utils/span.h>
16
17namespace lagrange {
18
19enum class Orientation : short {
20 Positive = 1,
21 Zero = 0,
22 Negative = -1
23}
24
35template <typename Scalar>
36Orientation triangle_orientation(
40{
41 const ExactPredicatesShewchuk predicates;
42 if constexpr (std::is_same_v<Scalar, double>) {
43 return static_cast<Orientation>(predicates.orient2D(
44 const_cast<double*>(a.data()),
45 const_cast<double*>(b.data()),
46 const_cast<double*>(c.data())));
47 } else {
48 double data[6]{
49 static_cast<double>(a[0]),
50 static_cast<double>(a[1]),
51 static_cast<double>(b[0]),
52 static_cast<double>(b[1]),
53 static_cast<double>(c[0]),
54 static_cast<double>(c[1])};
55 return static_cast<Orientation>(predicates.orient2D(data, data + 2, data + 4));
56 }
57}
58
59} // namespace lagrange
Definition: ExactPredicatesShewchuk.h:19
virtual short orient2D(double p1[2], double p2[2], double p3[2]) const
Exact 2D orientation test.
Definition: ExactPredicatesShewchuk.cpp:36
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition: span.h:27
Main namespace for Lagrange.
Definition: AABBIGL.h:30
enum lagrange::Orientation short triangle_orientation(span< const Scalar, 2 > a, span< const Scalar, 2 > b, span< const Scalar, 2 > c)
Compute orientation of a 2D triangle.
Definition: triangle_orientation_2d.h:36