<commit_before>const Plugin = require('./plugin')
const Ease = require('pixi-ease')
const exists = require('exists')

module.exports = class SnapZoom extends Plugin
{
    /**
     * @param {Viewport} parent
     * @param {number} width  the desired width to snap the zoom to (put 0 to ignore width)
     * @param {number} height  the desired height to snap the zoom to (put 0 to ignore height)
     * @param {object} options
     * @param {number} [options.time=1000]
     * @param {string|function} [options.ease=easeInOutSine] ease function or name (see http://easings.net/ for supported names)
     * @param {boolean} [options.removeOnComplete=true] removes this plugin after fitting is complete
     * @param {PIXI.Point} [options.center] place this point at center during zoom instead of center of the viewport
     * @param {boolean} [options.interrupt=true] pause snapping with any user input on the viewport
     *
     * @event snap-zoom-start(Viewport) emitted each time a fit animation starts
     * @event snap-zoom-end(Viewport) emitted each time fit reaches its target
     */
    constructor(parent, width, height, options)
    {
        super(parent)
        options = options || {}
        
        if (width > 0)
        {
            this.x_scale = parent._screenWidth / width
        }
        if (height > 0)
        {
            this.y_scale = parent._screenHeight / height
        }
        this.x_scale = exists(this.x_scale) ? this.x_scale : this.y_scale
        this.y_scale = exists(this.y_scale) ? this.y_scale : this.x_scale
        
        this.time = exists(options.time) ? options.time : 1000
        this.ease = options.ease || 'easeInOutSine'
        this.center = options.center
        this.stopOnResize = options.stopOnResize
        this.removeOnComplete = exists(options.removeOnComplete) ? options.removeOnComplete : true
        this.interrupt = exists(options.interrupt) ? options.interrupt : true
        
        if (this.time == 0)
        {
            parent.container.scale.x = this.x_scale
            parent.container.scale.y = this.y_scale
            
            if (this.removeOnComplete)
            {
                this.parent.removePlugin('fit')
            }
        }
    }

    reset()
    {
        this.snapping = null
    }

    down()
    {
        this.snapping = null
    }

    update(elapsed)
    {
        if (this.paused)
        {
            return
        }
        if (this.interrupt && this.parent.input.pointers.length !== 0)<commit_msg>Resize accurately updates SnapZoom<commit_after>const Plugin = require('./plugin')
const Ease = require('pixi-ease')
const exists = require('exists')

module.exports = class SnapZoom extends Plugin
{
    /**
     * @param {Viewport} parent
     * @param {number} width  the desired width to snap the zoom to (put 0 to ignore width)
     * @param {number} height  the desired height to snap the zoom to (put 0 to ignore height)
     * @param {object} options
     * @param {number} [options.time=1000]
     * @param {string|function} [options.ease=easeInOutSine] ease function or name (see http://easings.net/ for supported names)
     * @param {boolean} [options.removeOnComplete=true] removes this plugin after fitting is complete
     * @param {PIXI.Point} [options.center] place this point at center during zoom instead of center of the viewport
     * @param {boolean} [options.interrupt=true] pause snapping with any user input on the viewport
     *
     * @event snap-zoom-start(Viewport) emitted each time a fit animation starts
     * @event snap-zoom-end(Viewport) emitted each time fit reaches its target
     */
    constructor(parent, width, height, options)
    {
        super(parent)
        options = options || {}
        
        this.width = width
        this.height = height
        if (this.width > 0)
        {
            this.x_scale = parent._screenWidth / this.width
        }
        if (this.height > 0)
        {
            this.y_scale = parent._screenHeight / this.height
        }
        this.xIndependent = exists(this.x_scale)
        this.yIndependent = exists(this.y_scale)
        this.x_scale = this.xIndependent ? this.x_scale : this.y_scale
        this.y_scale = this.yIndependent ? this.y_scale : this.x_scale
        
        this.time = exists(options.time) ? options.time : 1000
        this.ease = options.ease || 'easeInOutSine'
        this.center = options.center
        this.stopOnResize = options.stopOnResize
        this.removeOnComplete = exists(options.removeOnComplete) ? options.removeOnComplete : true
        this.interrupt = exists(options.interrupt) ? options.interrupt : true
        
        if (this.time == 0)
        {
            parent.container.scale.x = this.x_scale
            parent.container.scale.y = this.y_scale
            
            if (this.removeOnComplete)
            {
                this.parent.removePlugin('fit')
            }
        }
    }
    
    resize()
    {
        this.snapping = null
        
        if (this.width > 0)
        {
            this.x_scale = parent._screenWidth / this.width
        }
        if (this.height > 0)
        {
            this.y_scale = parent._screenHeight / this.height
        }
        this.x_scale = this.xIndependent ? this.x_scale : this.y_scale
        this.y_scale = this.yIndependent ? this.y_scale : this.x_scale
    }
    
    reset()
    {
        this.snapping = null
    }

    down()
    {
        this.snapping = null
    }

    update(elapsed)
    {
        if (this.paused)
        {
            return
        }
        if (this.interrupt && this.parent.input.pointers.length !== 0)
{'fraction_non_alphanumeric': 0.10077793493635077, 'fraction_numerical': 0.005304101838755304, 'mean_word_length': 2.056185845488925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1498775', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1624, 'n_words': 419}