<commit_before>#include "Colors.h"
#include "ImageView.h"

namespace sg_gui {

ImageView::~ImageView() {

	if (_texture != 0)
		delete _texture;
}

void
ImageView::onSignal(DrawOpaque& /*signal*/) {

	if (_alpha < 1.0)
		return;

	draw();
}

void
ImageView::onSignal(DrawTranslucent& /*signal*/) {

	if (_alpha == 1.0)
		return;

	draw();
}

void
ImageView::onSignal(MouseDown& signal) {

	if (signal.button == buttons::Left) {

		util::point<float, 2> p = signal.ray.position().project<2>();
		if (!_image->getBoundingBox().contains(p))
			return;

		unsigned int x, y, z;
		_image->getDiscreteCoordinates(p.x(), p.y(), 0, x, y, z);
		LOG_USER(logger::out) << "value at position " << p << " is " << (*_image)(x, y, z) << std::endl;
	}
}

void
ImageView::draw() {

	// wait for image
	if (!_image)
		return;

	// wait for content
	if (_image->width() == 0 || _image->height() == 0)
		return;

	if (_needReload)
		loadTexture();

	glEnable(GL_TEXTURE_2D);
	glDisable(GL_CULL_FACE);

	_texture->bind();

	glColor4f(_red, _green, _blue, _alpha);

	const util::box<float,3>& bb = _image->getBoundingBox();
	float minX = bb.min().x();
	float minY = bb.min().y();
	float maxX = bb.max().x();<commit_msg>bugfix: fixed out-of-bounds access for left click in ImageView<commit_after>#include "Colors.h"
#include "ImageView.h"

namespace sg_gui {

ImageView::~ImageView() {

	if (_texture != 0)
		delete _texture;
}

void
ImageView::onSignal(DrawOpaque& /*signal*/) {

	if (_alpha < 1.0)
		return;

	draw();
}

void
ImageView::onSignal(DrawTranslucent& /*signal*/) {

	if (_alpha == 1.0)
		return;

	draw();
}

void
ImageView::onSignal(MouseDown& signal) {

	if (signal.button == buttons::Left) {

		util::point<float, 2> p = signal.ray.position().project<2>();
		if (!_image->getBoundingBox().contains(p))
			return;

		unsigned int x, y, _;
		_image->getDiscreteCoordinates(p.x(), p.y(), 0, x, y, _);
		LOG_USER(logger::out) << "value at position " << p << " is " << (*_image)(x, y, 0) << std::endl;
	}
}

void
ImageView::draw() {

	// wait for image
	if (!_image)
		return;

	// wait for content
	if (_image->width() == 0 || _image->height() == 0)
		return;

	if (_needReload)
		loadTexture();

	glEnable(GL_TEXTURE_2D);
	glDisable(GL_CULL_FACE);

	_texture->bind();

	glColor4f(_red, _green, _blue, _alpha);

	const util::box<float,3>& bb = _image->getBoundingBox();
	float minX = bb.min().x();
	float minY = bb.min().y();
	float maxX = bb.max().x();
{'fraction_non_alphanumeric': 0.19852640196479737, 'fraction_numerical': 0.011051985264019648, 'mean_word_length': 4.145263157894737, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 21, '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': '2300910', 'n_tokens_mistral': 1023, 'n_tokens_neox': 929, 'n_words': 209}