app/data/ct.libs/place.legacy/index.js
/**
         * Throws a ray from point (x1, y1) to (x2, y2), returning all the instances that touched the ray.
         * The first copy in the returned array is the closest copy, the last one is the furthest. 
         * 
         * @param {Number} x1 A horizontal coordinate of the starting point of the ray.
         * @param {Number} y1 A vertical coordinate of the starting point of the ray.
         * @param {Number} x2 A horizontal coordinate of the ending point of the ray.
         * @param {Number} y2 A vertical coordinate of the ending point of the ray.
         * @param {String} [ctype] An optional collision group to trace against. If omitted, will trace through all the copies in the current room.
         * 
         * @returns {Array<Copy>} Array of all the copies that touched the ray
         */
Throws a ray from point (x1, y1) to (x2, y2), returning all the instances that touched the ray.
The first copy in the returned array is the closest copy, the last one is the furthest.

@param {Number} x1 A horizontal coordinate of the starting point of the ray.
@param {Number} y1 A vertical coordinate of the starting point of the ray.
@param {Number} x2 A horizontal coordinate of the ending point of the ray.
@param {Number} y2 A vertical coordinate of the ending point of the ray.
@param {String} [ctype] An optional collision group to trace against. If omitted, will trace through all the copies in the current room.

@returns {Array} Array of all the copies that touched the ray
Throws a ray from point ( x1 y1 ) to ( x2 y2 ) returning all the instances that touched the ray . The first copy in the returned array is the closest copy the last one is the furthest . @param { Number } x1 A horizontal coordinate of the starting point of the ray . @param { Number } y1 A vertical coordinate of the starting point of the ray . @param { Number } x2 A horizontal coordinate of the ending point of the ray . @param { Number } y2 A vertical coordinate of the ending point of the ray . @param { String } [ ctype ] An optional collision group to trace against . If omitted will trace through all the copies in the current room . @returns { Array } Array of all the copies that touched the ray
trace(x1, y1, x2, y2, ctype) {
            var copies = [],
                ray = {
                    x: 0,
                    y: 0,
                    shape: {
                        type: 'line',
                        x1: x1,
                        y1: y1,
                        x2: x2,
                        y2: y2
                    }
                };
            for (var i in ct.stack) {
                if (!ctype || ct.stack[i].ctype === ctype) {
                    if (ct.place.collide(ray, ct.stack[i])) {
                        copies.push(ct.stack[i]);
                    }
                }
            }
            if (copies.length > 1) {
                copies.sort(function (a, b) {
                    var dist1, dist2;
                    dist1 = ct.u.pdc(x1, y1, a.x, a.y);
                    dist2 = ct.u.pdc(x1, y1, b.x, b.y);
                    if (a.shape.type === 'circle') {
                        if (dist1 > a.shape.r) {
                            dist1 -= a.shape.r;
                        } else {
                            dist1 = 0;
                        }
                    }
                    if (b.shape.type === 'circle') {
                        if (dist2 > b.shape.r) {
                            dist2 -= b.shape.r;
                        } else {
                            dist2 = 0;
                        }
                    }
                    if (a.shape.type === 'rect') {
                        if (ct.u.prect(x1, y1, a)) {
                            dist1 = 0;
                        } else {
                            dist1 = Math.min(dist1,
                                ct.u.pdc(x1, y1, a.x - a.shape.left, a.y - a.shape.top),
                                ct.u.pdc(x1, y1, a.x + a.shape.right, a.y - a.shape.top),
                                ct.u.pdc(x1, y1, a.x - a.shape.left, a.y + a.shape.bottom),
                                ct.u.pdc(x1, y1, a.x + a.shape.right, a.y + a.shape.bottom)
                            );
                        }
                    }
                    if (b.shape.type === 'rect') {
                        if (ct.u.prect(x1, y1, b)) {
                            dist2 = 0;
                        } else {
                            dist2 = Math.min(dist2,
                                ct.u.pdc(x1, y1, b.x - b.shape.left, b.y - b.shape.top),
                                ct.u.pdc(x1, y1, b.x + b.shape.right, b.y - b.shape.top),
                                ct.u.pdc(x1, y1, b.x - b.shape.left, b.y + b.shape.bottom),
                                ct.u.pdc(x1, y1, b.x + b.shape.right, b.y + b.shape.bottom)
                            );
                        }
                    }
                    return dist1 - dist2;
                });
            }
            return copies;
        }
trace ( x1 , y1 , x2 , y2 , ctype ) { var copies = [ ] , ray = { x : 0 , y : 0 , shape : { type : 'line' , x1 : x1 , y1 : y1 , x2 : x2 , y2 : y2 } } ; for ( var i in ct . stack ) { if ( ! ctype || ct . stack [ i ] . ctype === ctype ) { if ( ct . place . collide ( ray , ct . stack [ i ] ) ) { copies . push ( ct . stack [ i ] ) ; } } } if ( copies . length > 1 ) { copies . sort ( function ( a , b ) { var dist1 , dist2 ; dist1 = ct . u . pdc ( x1 , y1 , a . x , a . y ) ; dist2 = ct . u . pdc ( x1 , y1 , b . x , b . y ) ; if ( a . shape . type === 'circle' ) { if ( dist1 > a . shape . r ) { dist1 -= a . shape . r ; } else { dist1 = 0 ; } } if ( b . shape . type === 'circle' ) { if ( dist2 > b . shape . r ) { dist2 -= b . shape . r ; } else { dist2 = 0 ; } } if ( a . shape . type === 'rect' ) { if ( ct . u . prect ( x1 , y1 , a ) ) { dist1 = 0 ; } else { dist1 = Math . min ( dist1 , ct . u . pdc ( x1 , y1 , a . x - a . shape . left , a . y - a . shape . top ) , ct . u . pdc ( x1 , y1 , a . x + a . shape . right , a . y - a . shape . top ) , ct . u . pdc ( x1 , y1 , a . x - a . shape . left , a . y + a . shape . bottom ) , ct . u . pdc ( x1 , y1 , a . x + a . shape . right , a . y + a . shape . bottom ) ) ; } } if ( b . shape . type === 'rect' ) { if ( ct . u . prect ( x1 , y1 , b ) ) { dist2 = 0 ; } else { dist2 = Math . min ( dist2 , ct . u . pdc ( x1 , y1 , b . x - b . shape . left , b . y - b . shape . top ) , ct . u . pdc ( x1 , y1 , b . x + b . shape . right , b . y - b . shape . top ) , ct . u . pdc ( x1 , y1 , b . x - b . shape . left , b . y + b . shape . bottom ) , ct . u . pdc ( x1 , y1 , b . x + b . shape . right , b . y + b . shape . bottom ) ) ; } } return dist1 - dist2 ; } ) ; } return copies ; }
Throws a ray from point (x1, y1) to (x2, y2), returning all the instances that touched the ray.
Throws a ray from point ( x1 y1 ) to ( x2 y2 ) returning all the instances that touched the ray .
// if a starting point is *IN* the circle,  // then this point itself is a hit point // if a starting point is *IN* the circle,  // then this point itself is a hit point /* These are quick and dirty approximations;
                               they should be improved on par with `line.*` checks later
                               to get actual intersection points. */