# Path: gridded/pyugrid/util.py
# def point_in_tri(face_points, point, return_weights=False):
#     """
#     Calculates whether point is internal/external
#     to element by comparing summed area of sub triangles with area of triangle
#     element.
# 
#     NOTE: this seems like a pretty expensive way to do it
#            -- compared to three side of line tests..
#     """
#     sub_tri_areas = np.zeros(3)
#     sub_tri_areas[0] = _signed_area_tri(np.vstack((face_points[(0, 1), :],
#                                                    point)))
#     sub_tri_areas[1] = _signed_area_tri(np.vstack((face_points[(1, 2), :],
#                                                    point)))
#     sub_tri_areas[2] = _signed_area_tri(np.vstack((face_points[(0, 2), :],
#                                                    point)))
#     tri_area = _signed_area_tri(face_points)
# 
#     if abs(np.abs(sub_tri_areas).sum() - tri_area) / tri_area <= epsilon:
#         if return_weights:
#             raise NotImplementedError
#             # weights = sub_tri_areas/tri_area
#             # weights[1] = max(0., min(1., weights[1]))
#             # weights[2] = max(0., min(1., weights[2]))
#             # if (weights[0]+weights[1]>1):
#             #     weights[2] = 0
#             #     weights[1] = 1-weights[0]
#             # else:
#             #     weights[2] = 1-weights[0]-weights[1]
#             #
#             # return weights
#         else:
#             return True
#     return False


import numpy as np
from gridded.pyugrid.util import point_in_tri
from __future__ import (absolute_import, division, print_function)




def test_point_in_tri():
    test_datasets = [
        {
            'triangle': np.array([[0., 0.], [1., 0.], [0., 1.]]),
            'points_inside': [np.array([0.1, 0.1]), np.array([0.3, 0.3])],
            'points_outside': [np.array([5., 5.])],
        },
    ]

    for dataset in test_datasets:
        for point in dataset['points_inside']:
            assert point_in_tri(dataset['triangle'], point)
        for point in dataset['points_outside']:

# Path: gridded/pyugrid/util.py
# def point_in_tri(face_points, point, return_weights=False):
#     """
#     Calculates whether point is internal/external
#     to element by comparing summed area of sub triangles with area of triangle
#     element.
# 
#     NOTE: this seems like a pretty expensive way to do it
#            -- compared to three side of line tests..
#     """
#     sub_tri_areas = np.zeros(3)
#     sub_tri_areas[0] = _signed_area_tri(np.vstack((face_points[(0, 1), :],
#                                                    point)))
#     sub_tri_areas[1] = _signed_area_tri(np.vstack((face_points[(1, 2), :],
#                                                    point)))
#     sub_tri_areas[2] = _signed_area_tri(np.vstack((face_points[(0, 2), :],
#                                                    point)))
#     tri_area = _signed_area_tri(face_points)
# 
#     if abs(np.abs(sub_tri_areas).sum() - tri_area) / tri_area <= epsilon:
#         if return_weights:
#             raise NotImplementedError
#             # weights = sub_tri_areas/tri_area
#             # weights[1] = max(0., min(1., weights[1]))
#             # weights[2] = max(0., min(1., weights[2]))
#             # if (weights[0]+weights[1]>1):
#             #     weights[2] = 0
#             #     weights[1] = 1-weights[0]
#             # else:
#             #     weights[2] = 1-weights[0]-weights[1]
#             #
#             # return weights
#         else:
#             return True
#     return False


# Path: gridded/tests/test_ugrid/test_point_in_triangle.py
import numpy as np
from gridded.pyugrid.util import point_in_tri

from __future__ import (absolute_import, division, print_function)




def test_point_in_tri():
    test_datasets = [
        {
            'triangle': np.array([[0., 0.], [1., 0.], [0., 1.]]),
            'points_inside': [np.array([0.1, 0.1]), np.array([0.3, 0.3])],
            'points_outside': [np.array([5., 5.])],
        },
    ]

    for dataset in test_datasets:
        for point in dataset['points_inside']:
            assert point_in_tri(dataset['triangle'], point)
        for point in dataset['points_outside']:

            assert ~point_in_tri(dataset['triangle'], point)