<commit_before>//
// Implementation of methods for the basic data classes
//
// Copyright (c) 2001 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

#include "MathTypes.h"

//
// Return the index of the polygon at a specified point, or
// -1 if there is no polygon there.
//
// For speed, it first test the polygon which was found
// last time.  For spatially linear testing, this is a 10x
// speedup.
//
int DPolyArray2::FindPoly(DPoint2 p)
{
	if (m_previous_poly != -1)
	{
		if (GetAt(m_previous_poly)->ContainsPoint(p))
			return m_previous_poly;
	}
	int size = GetSize();
	for (int i = 0; i < size; i++)
	{
		DLine2 *poly = GetAt(i);
#if 0
		// possible further speed test: first test against extents
		if (world_x < poly->xmin || world_x > poly->xmax ||
			world_z < poly->zmin || world_z > poly->zmax)
			continue;
#endif
		if (poly->ContainsPoint(p))
		{
			// found
			m_previous_poly = i;
			return i;
		}
	}
	// not found
	m_previous_poly = -1;
	return -1;
}

//
// DLine2 methods
//

void DLine2::RemovePoint(int i)
{
	int size = GetSize();
	for (int x=i; x < size-1; x++)
		SetAt(x, GetAt(x+1));
	SetSize(GetSize()-1);
}

bool DLine2::ContainsPoint(const DPoint2 &p)
{
	return CrossingsTest(GetData(), GetSize(), p);
}
<commit_msg>added safety check to DLine2::ContainsPoint<commit_after>//
// Implementation of methods for the basic data classes
//
// Copyright (c) 2001 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

#include "MathTypes.h"

//
// Return the index of the polygon at a specified point, or
// -1 if there is no polygon there.
//
// For speed, it first test the polygon which was found
// last time.  For spatially linear testing, this is a 10x
// speedup.
//
int DPolyArray2::FindPoly(DPoint2 p)
{
	if (m_previous_poly != -1)
	{
		if (GetAt(m_previous_poly)->ContainsPoint(p))
			return m_previous_poly;
	}
	int size = GetSize();
	for (int i = 0; i < size; i++)
	{
		DLine2 *poly = GetAt(i);
#if 0
		// possible further speed test: first test against extents
		if (world_x < poly->xmin || world_x > poly->xmax ||
			world_z < poly->zmin || world_z > poly->zmax)
			continue;
#endif
		if (poly->ContainsPoint(p))
		{
			// found
			m_previous_poly = i;
			return i;
		}
	}
	// not found
	m_previous_poly = -1;
	return -1;
}

//
// DLine2 methods
//

void DLine2::RemovePoint(int i)
{
	int size = GetSize();
	for (int x=i; x < size-1; x++)
		SetAt(x, GetAt(x+1));
	SetSize(GetSize()-1);
}

bool DLine2::ContainsPoint(const DPoint2 &p)
{
	if (GetData() != NULL)
		return CrossingsTest(GetData(), GetSize(), p);
	else
		return false;
}

{'fraction_non_alphanumeric': 0.1468904998092331, 'fraction_numerical': 0.01716901945822205, 'mean_word_length': 3.1818181818181817, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3927670', 'n_tokens_mistral': 1036, 'n_tokens_neox': 967, 'n_words': 302}