<commit_before>//------------------------------------------------------------------------------
//  panDetector.cc
//------------------------------------------------------------------------------
#include "Pre.h"
#include "Core/Assert.h"
#include "panDetector.h"

namespace Oryol {
namespace _priv {
    
//------------------------------------------------------------------------------
void
panDetector::reset() {
    if (this->startEvent.type != touch::invalid) {
        this->startEvent = touch();
    }
    this->panning = false;
}

//------------------------------------------------------------------------------
bool
panDetector::distLess(const glm::vec2& pos0, const glm::vec2& pos1, float dist) const {
    float dx = pos1.x - pos0.x;
    float dy = pos1.y - pos0.y;
    return (dx * dx + dy * dy) < (dist * dist);
}

//------------------------------------------------------------------------------
gestureState::Code
panDetector::detect(const touch& newEvent) {
    o_assert_dbg(newEvent.numTouches > 0);
    
    // check for cancelled event
    if (newEvent.type == touch::cancelled) {
        this->reset();
        return gestureState::none;
    }
    
    // ignore/cancel if not required number of touches or touch id's have changed
    if (1 != newEvent.numTouches) {
        this->reset();
        return gestureState::none;
    }
    
    // check if events identifiers match
    if ((this->startEvent.type != touch::invalid) && !this->startEvent.sameTouches(newEvent)) {
        this->reset();
        return gestureState::none;
    }
    
    // number of required touches is ok now,
    // check whether to start, move or end panning
    if (newEvent.type == touch::began) {
        this->startEvent = newEvent;
        this->startPosition = newEvent.touchPos(newEvent.points[0].identifier);
        this->position = this->startPosition;
        this->panning = false;
        return gestureState::none;
    }
    else if (newEvent.type == touch::moved) {
        // cancel if start event is not valid
        if (this->startEvent.type == touch::invalid) {
            return gestureState::none;
        }

        // for multitouch panning, check if distance between fingers
        // has changes too much
        // FIXME!
        
        
        this->position = newEvent.touchPos(this->startEvent.points[0].identifier);
        if (this->panning) {
            // already panning
            return gestureState::move;
        }
        else {
            // not yet panning, check if min-distance is reached before starting pan,
            // and if yes, start panning
            if (!this->distLess(this->startPosition, this->position, MinMovedDistance)) {
                this->panning = true;
                return gestureState::start;
            }
            else {<commit_msg>removed obsolete comment<commit_after>//------------------------------------------------------------------------------
//  panDetector.cc
//------------------------------------------------------------------------------
#include "Pre.h"
#include "Core/Assert.h"
#include "panDetector.h"

namespace Oryol {
namespace _priv {
    
//------------------------------------------------------------------------------
void
panDetector::reset() {
    if (this->startEvent.type != touch::invalid) {
        this->startEvent = touch();
    }
    this->panning = false;
}

//------------------------------------------------------------------------------
bool
panDetector::distLess(const glm::vec2& pos0, const glm::vec2& pos1, float dist) const {
    float dx = pos1.x - pos0.x;
    float dy = pos1.y - pos0.y;
    return (dx * dx + dy * dy) < (dist * dist);
}

//------------------------------------------------------------------------------
gestureState::Code
panDetector::detect(const touch& newEvent) {
    o_assert_dbg(newEvent.numTouches > 0);
    
    // check for cancelled event
    if (newEvent.type == touch::cancelled) {
        this->reset();
        return gestureState::none;
    }
    
    // ignore/cancel if not required number of touches or touch id's have changed
    if (1 != newEvent.numTouches) {
        this->reset();
        return gestureState::none;
    }
    
    // check if events identifiers match
    if ((this->startEvent.type != touch::invalid) && !this->startEvent.sameTouches(newEvent)) {
        this->reset();
        return gestureState::none;
    }
    
    // number of required touches is ok now,
    // check whether to start, move or end panning
    if (newEvent.type == touch::began) {
        this->startEvent = newEvent;
        this->startPosition = newEvent.touchPos(newEvent.points[0].identifier);
        this->position = this->startPosition;
        this->panning = false;
        return gestureState::none;
    }
    else if (newEvent.type == touch::moved) {
        // cancel if start event is not valid
        if (this->startEvent.type == touch::invalid) {
            return gestureState::none;
        }
        
        this->position = newEvent.touchPos(this->startEvent.points[0].identifier);
        if (this->panning) {
            // already panning
            return gestureState::move;
        }
        else {
            // not yet panning, check if min-distance is reached before starting pan,
            // and if yes, start panning
            if (!this->distLess(this->startPosition, this->position, MinMovedDistance)) {
                this->panning = true;
                return gestureState::start;
            }
            else {
{'fraction_non_alphanumeric': 0.25072568940493467, 'fraction_numerical': 0.0043541364296081275, 'mean_word_length': 1.4275649493615148, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '4877937', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1409, 'n_words': 355}