Lagrange
Loading...
Searching...
No Matches
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/ExactPredicatesShewchuk.h>
15#include <lagrange/utils/span.h>
16
17namespace lagrange {
18
19enum class Orientation : short { Positive = 1, Zero = 0, Negative = -1 };
20
31template <typename Scalar>
32Orientation
34{
35 const ExactPredicatesShewchuk predicates;
36 if constexpr (std::is_same_v<Scalar, double>) {
37 return static_cast<Orientation>(predicates.orient2D(
38 const_cast<double*>(a.data()),
39 const_cast<double*>(b.data()),
40 const_cast<double*>(c.data())));
41 } else {
42 double data[6]{
43 static_cast<double>(a[0]),
44 static_cast<double>(a[1]),
45 static_cast<double>(b[0]),
46 static_cast<double>(b[1]),
47 static_cast<double>(c[0]),
48 static_cast<double>(c[1])};
49 return static_cast<Orientation>(predicates.orient2D(data, data + 2, data + 4));
50 }
51}
52
53} // 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:37
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition span.h:27
Main namespace for Lagrange.
Orientation 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:33