<commit_before>/*
 * BezierCurve.h
 *
 * Copyright (C) 2006 - 2008 by Universitaet Stuttgart (VIS).
 * Copyright (C) 2006 - 2009 by Universitaet Stuttgart (VISUS).
 * Alle Rechte vorbehalten.
 */

#ifndef VISLIB_BEZIERCURVE_H_INCLUDED
#define VISLIB_BEZIERCURVE_H_INCLUDED
#if (defined(_MSC_VER) && (_MSC_VER > 1000))
#pragma once
#endif /* (defined(_MSC_VER) && (_MSC_VER > 1000)) */
#if defined(_WIN32) && defined(_MANAGED)
#pragma managed(push, off)
#endif /* defined(_WIN32) && defined(_MANAGED) */

#include "vislib/forceinline.h"
#include "vislib/OutOfRangeException.h"
#include "vislib/Point.h"
#include "vislib/Vector.h"


namespace vislib {
namespace math {


    /**
     * Stores and evaluates a bzier curve of degree E. The curve is defined
     * by E + 1 control points (type T) forming the control polygon.
     *
     * Template parameters:
     *  T type (e. g. Point<float, 3>); Must support the method
     *    'Interpolate(rhs, float t)' with 0 <= t <= 1 for linear
     *    interpolation
     *  E Degree
     */
    template <class T, unsigned int E>
    class BezierCurve {
    public:

        /**
         * Ctor.
         * Creates an empty curve with all control points placed in the
         * origin.
         */
        BezierCurve(void);

        /** Dtor. */
        ~BezierCurve(void);

        /*
         * Evaluates the position on the bzier curve for the
         * interpolation parameter t based on the algorithm of de Casteljau.
         *
         * @param outPt The variable to be set to the calculated point.
         * @param t The interpolation parameter (0..1); Results for values
         *          outside this range are undefined.
         *
         * @return The same reference as 'outPt'
         */
        T& CalcPoint(T& outPt, float t) const;

        /**
         * Calculates the tangent along the curve for the interpolation
         * value t.
         *
         * @param outVec The variable to be set. The type must be compatible
         *               with the result type of the 'operator -' of the
         *               template type T.
         * @param t The interpolation parameter (0..1); Results for values
         *          outside this range are undefined.
         *
         * @return The same reference as 'outVec'
         */
        template<class Tp>
        Tp& CalcTangent(Tp& outVec, float t) const;

        /**
         * Accesses the idx-th control point
         *
         * @param idx The index of the control point to be set (0..E)
         *
         * @return A reference to the idx-th control point
         */
        T& ControlPoint(unsigned int idx);

        /**
         * Accesses the idx-th control point read-only
         *
         * @param idx The index of the control point to be set (0..E)
         *
         * @return A const reference to the idx-th control point
         */
        const T& ControlPoint(unsigned int idx) const;

        /**
         * Evaluates the position on the bzier curve for the
         * interpolation parameter t based on the algorithm of de Casteljau.
         *
         * @param t The interpolation parameter (0..1); Results for values
         *          outside this range are undefined.
         *
         * @return The position on the bzier curve
         */
        VISLIB_FORCEINLINE T Evaluate(float t) const {
            T rv;
            return this->CalcPoint(rv, t);
        }

        /**
         * Sets the idx-th control point
         *
         * @param idx The index of the control point to be set (0..E)
         * @param p The new value for the control point
         */
        VISLIB_FORCEINLINE void SetControlPoint(unsigned int idx, T& p) {
            this->ControlPoint(idx) = p;
        }

        /**
         * Evaluates the position on the bzier curve for the
         * interpolation parameter t based on the algorithm of de Casteljau.
         *
         * @param t The interpolation parameter (0..1); Results for values
         *          outside this range are undefined.
         *
         * @return The position on the bzier curve
         */
        VISLIB_FORCEINLINE T operator()(float t) const {
            T rv;
            return this->CalcPoint(rv, t);
        }

        /**
         * Test for equality.
         *
         * @param rhs The right hand side operand
         *
         * @return 'true' if 'this' and 'rhs' are equal, 'false' if not.
         */
        bool operator==(const BezierCurve<T, E>& rhs) const;

    private:

        /** control points */<commit_msg>BezierCurve::operator[] for convenience access to the control points.<commit_after>/*
 * BezierCurve.h
 *
 * Copyright (C) 2006 - 2008 by Universitaet Stuttgart (VIS).
 * Copyright (C) 2006 - 2009 by Universitaet Stuttgart (VISUS).
 * Alle Rechte vorbehalten.
 */

#ifndef VISLIB_BEZIERCURVE_H_INCLUDED
#define VISLIB_BEZIERCURVE_H_INCLUDED
#if (defined(_MSC_VER) && (_MSC_VER > 1000))
#pragma once
#endif /* (defined(_MSC_VER) && (_MSC_VER > 1000)) */
#if defined(_WIN32) && defined(_MANAGED)
#pragma managed(push, off)
#endif /* defined(_WIN32) && defined(_MANAGED) */

#include "vislib/forceinline.h"
#include "vislib/OutOfRangeException.h"
#include "vislib/Point.h"
#include "vislib/Vector.h"


namespace vislib {
namespace math {


    /**
     * Stores and evaluates a bzier curve of degree E. The curve is defined
     * by E + 1 control points (type T) forming the control polygon.
     *
     * Template parameters:
     *  T type (e. g. Point<float, 3>); Must support the method
     *    'Interpolate(rhs, float t)' with 0 <= t <= 1 for linear
     *    interpolation
     *  E Degree
     */
    template <class T, unsigned int E>
    class BezierCurve {
    public:

        /**
         * Ctor.
         * Creates an empty curve with all control points placed in the
         * origin.
         */
        BezierCurve(void);

        /** Dtor. */
        ~BezierCurve(void);

        /*
         * Evaluates the position on the bzier curve for the
         * interpolation parameter t based on the algorithm of de Casteljau.
         *
         * @param outPt The variable to be set to the calculated point.
         * @param t The interpolation parameter (0..1); Results for values
         *          outside this range are undefined.
         *
         * @return The same reference as 'outPt'
         */
        T& CalcPoint(T& outPt, float t) const;

        /**
         * Calculates the tangent along the curve for the interpolation
         * value t.
         *
         * @param outVec The variable to be set. The type must be compatible
         *               with the result type of the 'operator -' of the
         *               template type T.
         * @param t The interpolation parameter (0..1); Results for values
         *          outside this range are undefined.
         *
         * @return The same reference as 'outVec'
         */
        template<class Tp>
        Tp& CalcTangent(Tp& outVec, float t) const;

        /**
         * Accesses the idx-th control point
         *
         * @param idx The index of the control point to be set (0..E)
         *
         * @return A reference to the idx-th control point
         */
        T& ControlPoint(unsigned int idx);

        /**
         * Accesses the idx-th control point read-only
         *
         * @param idx The index of the control point to be set (0..E)
         *
         * @return A const reference to the idx-th control point
         */
        const T& ControlPoint(unsigned int idx) const;

        /**
         * Evaluates the position on the bzier curve for the
         * interpolation parameter t based on the algorithm of de Casteljau.
         *
         * @param t The interpolation parameter (0..1); Results for values
         *          outside this range are undefined.
         *
         * @return The position on the bzier curve
         */
        VISLIB_FORCEINLINE T Evaluate(float t) const {
            T rv;
            return this->CalcPoint(rv, t);
        }

        /**
         * Sets the idx-th control point
         *
         * @param idx The index of the control point to be set (0..E)
         * @param p The new value for the control point
         */
        VISLIB_FORCEINLINE void SetControlPoint(unsigned int idx, T& p) {
            this->ControlPoint(idx) = p;
        }

        /**
         * Evaluates the position on the bzier curve for the
         * interpolation parameter t based on the algorithm of de Casteljau.
         *
         * @param t The interpolation parameter (0..1); Results for values
         *          outside this range are undefined.
         *
         * @return The position on the bzier curve
         */
        VISLIB_FORCEINLINE T operator()(float t) const {
            T rv;
            return this->CalcPoint(rv, t);
        }

        /**
         * Accesses the idx-th control point
         *
         * @param idx The index of the control point to be set (0..E)
         *
         * @return A reference to the idx-th control point
         */
        VISLIB_FORCEINLINE T& operator[](unsigned int idx) {
            return this->ControlPoint(idx);
        }

        /**
         * Accesses the idx-th control point read-only
         *
         * @param idx The index of the control point to be set (0..E)
         *
         * @return A const reference to the idx-th control point
         */
        VISLIB_FORCEINLINE const T& operator[](unsigned int idx) const {
            return this->ControlPoint(idx);
        }

        /**
         * Test for equality.
         *
         * @param rhs The right hand side operand
         *
         * @return 'true' if 'this' and 'rhs' are equal, 'false' if not.
         */
        bool operator==(const BezierCurve<T, E>& rhs) const;

    private:

        /** control points */
{'fraction_non_alphanumeric': 0.08922083165119096, 'fraction_numerical': 0.008881711748082357, 'mean_word_length': 1.7312568908489525, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '4802967', 'n_tokens_mistral': 2862, 'n_tokens_neox': 2715, 'n_words': 1025}