<commit_before>/**
 * geometry/triangle-view - geometry triangle array views
 * Part of Stardazed
 * (c) 2015-Present by <NAME> - @zenmumbler
 * https://github.com/stardazed/stardazed
 */

namespace sd {

export function triangleViewForIndexBuffer(ib: IndexBuffer): TriangleView {
	return new IndexBufferTriangleView(ib);
}

/**
 * @expects geom.subMeshes.every(sm => sm.type === PrimitiveType.Triangle)
 */
export function triangleViewForGeometry(geom: Geometry) {
	if (geom.indexBuffer) {
		return new IndexBufferTriangleView(geom.indexBuffer);
	}

	const elementCount = geom.subMeshes.map(sm => sm.elementCount).reduce((sum, count) => sum + count, 0);
	return new DirectTriangleView(elementCount);
}

/**
 * @expects geom.subMeshes[subMeshIndex] !== undefined
 * @expects geom.subMeshes[subMeshIndex].type === PrimitiveType.Triangle
 */
export function triangleViewForSubMesh(geom: Geometry, subMeshIndex: number) {
	const subMesh = geom.subMeshes[subMeshIndex];
	const fromTriangle = primitiveCountForElementCount(PrimitiveType.Triangle, subMesh.fromElement);
	const toTriangle = fromTriangle + primitiveCountForElementCount(PrimitiveType.Triangle, subMesh.elementCount);

	if (geom.indexBuffer) {
		return new IndexBufferTriangleView(geom.indexBuffer, fromTriangle, toTriangle);
	}
	return new DirectTriangleView(subMesh.elementCount, fromTriangle, toTriangle);
}

} // ns sd<commit_msg>ref(geom): add public helpers to check triangle-ness<commit_after>/**
 * geometry/triangle-view - geometry triangle array views
 * Part of Stardazed
 * (c) 2015-Present by <NAME> - @zenmumbler
 * https://github.com/stardazed/stardazed
 */

namespace sd {

export function triangleViewForIndexBuffer(ib: IndexBuffer): TriangleView {
	return new IndexBufferTriangleView(ib);
}

export function triangleViewSupportedOnGeometry(geom: Geometry) {
	return geom.subMeshes.every(sm => sm.type === PrimitiveType.Triangle);
}

/**
 * @expects triangleViewSupportedOnGeometry(geom)
 */
export function triangleViewForGeometry(geom: Geometry) {
	if (geom.indexBuffer) {
		return new IndexBufferTriangleView(geom.indexBuffer);
	}

	const elementCount = geom.subMeshes.map(sm => sm.elementCount).reduce((sum, count) => sum + count, 0);
	return new DirectTriangleView(elementCount);
}

export function triangleViewSupportedOnSubMesh(geom: Geometry, subMeshIndex: number) {
	return geom.subMeshes[subMeshIndex] !== undefined &&
		geom.subMeshes[subMeshIndex].type === PrimitiveType.Triangle;
}

/**
 * @expects triangleViewSupportedOnSubMesh(geom, subMeshIndex)
 */
export function triangleViewForSubMesh(geom: Geometry, subMeshIndex: number) {
	const subMesh = geom.subMeshes[subMeshIndex];
	const fromTriangle = primitiveCountForElementCount(PrimitiveType.Triangle, subMesh.fromElement);
	const toTriangle = fromTriangle + primitiveCountForElementCount(PrimitiveType.Triangle, subMesh.elementCount);

	if (geom.indexBuffer) {
		return new IndexBufferTriangleView(geom.indexBuffer, fromTriangle, toTriangle);
	}
	return new DirectTriangleView(subMesh.elementCount, fromTriangle, toTriangle);
}

} // ns sd
{'fraction_non_alphanumeric': 0.11258922777417261, 'fraction_numerical': 0.003244646333549643, 'mean_word_length': 6.254117647058823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '4544576', 'n_tokens_mistral': 990, 'n_tokens_neox': 957, 'n_words': 193}