Lagrange
quad_area.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#include <lagrange/utils/span.h>
14#include <lagrange/utils/triangle_area.h>
15
16namespace lagrange {
17
27template <typename Scalar>
33{
34 Scalar _center[2]{(a[0] + b[0] + c[0] + d[0]) / 4, (a[1] + b[1] + c[1] + d[1]) / 4};
35 span<const Scalar, 2> center(_center, 2);
36 return triangle_area_2d(a, b, center) + triangle_area_2d(b, c, center) +
37 triangle_area_2d(c, d, center) + triangle_area_2d(d, a, center);
38}
39
49template <typename Scalar>
55{
56 Scalar _center[3]{
57 (a[0] + b[0] + c[0] + d[0]) / 4,
58 (a[1] + b[1] + c[1] + d[1]) / 4,
59 (a[2] + b[2] + c[2] + d[2]) / 4};
60 span<const Scalar, 3> center(_center, 3);
61 return triangle_area_3d(a, b, center) + triangle_area_3d(b, c, center) +
62 triangle_area_3d(c, d, center) + triangle_area_3d(d, a, center);
63}
64
65} // namespace lagrange
::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
Scalar quad_area_2d(span< const Scalar, 2 > a, span< const Scalar, 2 > b, span< const Scalar, 2 > c, span< const Scalar, 2 > d)
Compute 2D quad signed area.
Definition: quad_area.h:28
Scalar quad_area_3d(span< const Scalar, 3 > a, span< const Scalar, 3 > b, span< const Scalar, 3 > c, span< const Scalar, 3 > d)
Compute 3D quad area.
Definition: quad_area.h:50
Scalar triangle_area_2d(span< const Scalar, 2 > a, span< const Scalar, 2 > b, span< const Scalar, 2 > c)
Compute 2D triangle signed area.
Definition: triangle_area.h:48
Scalar triangle_area_3d(span< const Scalar, 3 > a, span< const Scalar, 3 > b, span< const Scalar, 3 > c)
Compute 3D triangle area.
Definition: triangle_area.h:29