<commit_before>/*global define*/
define([
        '../Core/defaultValue',
        '../Core/Cartesian3',
        '../Core/Cartographic',
        '../Core/DeveloperError',
        '../Core/Ellipsoid',
        '../Core/HermiteSpline',
        '../Core/IntersectionTests',
        '../Core/Math',
        '../Core/Matrix3',
        '../Core/OrientationInterpolator',
        '../Core/Quaternion',
        '../Core/Ray',
        '../ThirdParty/Tween'
    ], function(
        defaultValue,
        Cartesian3,
        Cartographic,
        DeveloperError,
        Ellipsoid,
        HermiteSpline,
        IntersectionTests,
        CesiumMath,
        Matrix3,
        OrientationInterpolator,
        Quaternion,
        Ray,
        Tween) {
    "use strict";

    var CameraFlightPath = {
    };

    function createQuaternion(direction, up) {
        var right = direction.cross(up);
        up = right.cross(direction);
        var viewMat = new Matrix3( right.x,      right.y,      right.z,
                                   up.x,         up.y,         up.z,
                                  -direction.x, -direction.y, -direction.z);
        return Quaternion.fromRotationMatrix(viewMat);
    }

    function createPath(camera, ellipsoid, end, duration) {
        var start = camera.position;

        // get minimum altitude from which the whole ellipsoid is visible
        var radius = ellipsoid.getMaximumRadius();

        var frustum = camera.frustum;
        var near = frustum.near;
        var tanTheta = Math.tan(0.5 * frustum.fovy);
        var top = frustum.near * tanTheta;
        var right = frustum.aspectRatio * top;

        var dx = radius * near / right;
        var dy = radius * near / top;
        var maxStartAlt = Math.max(dx, dy);

        var dot = start.normalize().dot(end.normalize());
        var diff = end.subtract(start);
        var diffMag = diff.magnitude();
        var ray = new Ray(end, diff.normalize());
        var intersection = IntersectionTests.rayEllipsoid(ray, ellipsoid);

        var points;
        if (dot > 0.9 && (typeof intersection === 'undefined' || intersection.start > diffMag)) {
            points = [ { point : start }, { point: end }];
        } else {
            var altitude, incrementPercentage;
            if (start.magnitude() > maxStartAlt) {
                altitude = radius + 0.6 * (maxStartAlt - radius);
                incrementPercentage = 0.35;
            } else {
                var tanPhi = frustum.aspectRatio * tanTheta;
                diff = start.subtract(end);
                altitude = diff.multiplyByScalar(0.5).add(end).magnitude();
                var verticalDistance = camera.up.multiplyByScalar(diff.dot(camera.up)).magnitude();
                var horizontalDistance = camera.right.multiplyByScalar(diff.dot(camera.right)).magnitude();
                altitude += Math.max(verticalDistance / tanTheta, horizontalDistance / tanPhi);
                incrementPercentage = CesiumMath.clamp(dot + 1.0, 0.25, 0.5);
            }

            var cart = ellipsoid.cartesianToCartographic(end);
            cart.height = altitude;
            var aboveEnd = ellipsoid.cartographicToCartesian(cart);
            cart = ellipsoid.cartesianToCartographic(start);
            cart.height = altitude;
            var afterStart = ellipsoid.cartographicToCartesian(cart);

            var axis, angle, rotation;
            if (start.magnitude() > maxStartAlt && dot > 0) {
                var middle = start.subtract(aboveEnd).multiplyByScalar(0.5).add(aboveEnd);

                points = [{
                    point : start
                }, {
                    point : middle
                }, {
                    point : end
                }];
            } else {
                points = [{
                    point : start
                }];

                angle = Math.acos(afterStart.normalize().dot(aboveEnd.normalize()));
                axis = afterStart.cross(aboveEnd);

                var increment = incrementPercentage * angle;
                var startCondition = angle - increment;
                for ( var i = startCondition; i > 0.0; i = i - increment) {
                    rotation = Matrix3.fromQuaternion(Quaternion.fromAxisAngle(axis, i));
                    points.push({
                        point : rotation.multiplyByVector(aboveEnd)
                    });
                }

                points.push({
                    point : end
                });
            }
        }

        var scalar = duration / (points.length - 1);
        for ( var k = 0; k < points.length; ++k) {
            points[k].time = k * scalar;<commit_msg>Adjust to not fly to high altitudes for close points.<commit_after>/*global define*/
define([
        '../Core/defaultValue',
        '../Core/Cartesian3',
        '../Core/Cartographic',
        '../Core/DeveloperError',
        '../Core/Ellipsoid',
        '../Core/HermiteSpline',
        '../Core/IntersectionTests',
        '../Core/Math',
        '../Core/Matrix3',
        '../Core/OrientationInterpolator',
        '../Core/Quaternion',
        '../Core/Ray',
        '../ThirdParty/Tween'
    ], function(
        defaultValue,
        Cartesian3,
        Cartographic,
        DeveloperError,
        Ellipsoid,
        HermiteSpline,
        IntersectionTests,
        CesiumMath,
        Matrix3,
        OrientationInterpolator,
        Quaternion,
        Ray,
        Tween) {
    "use strict";

    var CameraFlightPath = {
    };

    function createQuaternion(direction, up) {
        var right = direction.cross(up);
        up = right.cross(direction);
        var viewMat = new Matrix3( right.x,      right.y,      right.z,
                                   up.x,         up.y,         up.z,
                                  -direction.x, -direction.y, -direction.z);
        return Quaternion.fromRotationMatrix(viewMat);
    }

    function createPath(camera, ellipsoid, end, duration) {
        var start = camera.position;

        // get minimum altitude from which the whole ellipsoid is visible
        var radius = ellipsoid.getMaximumRadius();

        var frustum = camera.frustum;
        var near = frustum.near;
        var tanTheta = Math.tan(0.5 * frustum.fovy);
        var top = frustum.near * tanTheta;
        var right = frustum.aspectRatio * top;

        var dx = radius * near / right;
        var dy = radius * near / top;
        var maxStartAlt = Math.max(dx, dy);

        var dot = start.normalize().dot(end.normalize());

        var points;
        var altitude;
        var incrementPercentage;
        if (start.magnitude() > maxStartAlt) {
            altitude = radius + 0.6 * (maxStartAlt - radius);
            incrementPercentage = 0.35;
        } else {
            var tanPhi = frustum.aspectRatio * tanTheta;
            var diff = start.subtract(end);
            altitude = diff.multiplyByScalar(0.5).add(end).magnitude();
            var verticalDistance = camera.up.multiplyByScalar(diff.dot(camera.up)).magnitude();
            var horizontalDistance = camera.right.multiplyByScalar(diff.dot(camera.right)).magnitude();
            altitude += Math.max(verticalDistance / tanTheta, horizontalDistance / tanPhi);
            incrementPercentage = CesiumMath.clamp(dot + 1.0, 0.25, 0.5);
        }

        var aboveEnd = end.normalize().multiplyByScalar(altitude);
        var afterStart = start.normalize().multiplyByScalar(altitude);

        var axis, angle, rotation;
        if (start.magnitude() > maxStartAlt && dot > 0) {
            var middle = start.subtract(aboveEnd).multiplyByScalar(0.5).add(aboveEnd);

            points = [{
                point : start
            }, {
                point : middle
            }, {
                point : end
            }];
        } else {
            points = [{
                point : start
            }];

            angle = Math.acos(afterStart.normalize().dot(aboveEnd.normalize()));
            axis = afterStart.cross(aboveEnd);

            var increment = incrementPercentage * angle;
            var startCondition = angle - increment;
            for ( var i = startCondition; i > 0.0; i = i - increment) {
                rotation = Matrix3.fromQuaternion(Quaternion.fromAxisAngle(axis, i));
                points.push({
                    point : rotation.multiplyByVector(aboveEnd)
                });
            }

            points.push({
                point : end
            });
        }

        var scalar = duration / (points.length - 1);
        for ( var k = 0; k < points.length; ++k) {
            points[k].time = k * scalar;
{'fraction_non_alphanumeric': 0.11644547028274668, 'fraction_numerical': 0.006924408540103866, 'mean_word_length': 1.5738045738045738, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4489866', 'n_tokens_mistral': 2477, 'n_tokens_neox': 2339, 'n_words': 502}