<commit_before>package org.spash.intersect;

import org.spash.ROVector2f;
import org.spash.ray.Ray;

public abstract class BaseRayShapeIntersector implements RayShapeIntersector {
    protected LineIntersector intersector;

    protected BaseRayShapeIntersector() {
        intersector = new LineIntersector();
    }

    /**
     * Finds intersection point of a ray and a line.
     * 
     * @param ray The ray
     * @param start Line start point
     * @param end Line end point
     * @return Intersection point or null if there is none. If the ray 
     * intersects the line at more than a single point, the intersection point
     * closest to the ray's origin is returned.
     */
    protected ROVector2f findIntersectionPoint(Ray ray, ROVector2f start, ROVector2f end) {
        IntersectionState state = intersector.determineIntersection(
                ray.getStart().getX(),
                ray.getStart().getY(),
                ray.getEnd().getX(),
                ray.getEnd().getY(),
                start.getX(),
                start.getY(),
                end.getX(),
                end.getY());

        if(state instanceof IntersectionState.Intersecting) {
            return state.getPoint();
        } else if(state instanceof IntersectionState.Colinear) {
            if(lineContainsRayStart(ray, start, end)) {
                return ray.getStart();
            }
            return ray.getStart().closest(endpointsWithinRay(ray, start, end));
        }
        return null;
    }

    //assumes ray and endpoints are colinear
    private ROVector2f[] endpointsWithinRay(Ray ray, ROVector2f start, ROVector2f end) {
        ROVector2f[] possibleIntersects = new ROVector2f[2]; 
        if(intersector.isPointWithinColinearSegment(start, ray.getStart(), ray.getEnd())) {
            possibleIntersects[0] = start;
        }
        if(intersector.isPointWithinColinearSegment(end, ray.getStart(), ray.getEnd())) {
            possibleIntersects[1] = end;
        }
        return possibleIntersects;
    }

    //assumes line and point are colinear
    private boolean lineContainsRayStart(Ray ray, ROVector2f start, ROVector2f end) {
        return intersector.isPointWithinColinearSegment(ray.getStart(), start, end);
    }
}<commit_msg>breaking out for reuse<commit_after>package org.spash.intersect;

import org.spash.ROVector2f;
import org.spash.ray.Ray;

public abstract class BaseRayShapeIntersector implements RayShapeIntersector {
    protected LineIntersector intersector;

    protected BaseRayShapeIntersector() {
        intersector = new LineIntersector();
    }

    /**
     * Finds intersection point of a ray and a line.
     * 
     * @param ray The ray
     * @param start Line start point
     * @param end Line end point
     * @return Intersection point or null if there is none. If the ray 
     * intersects the line at more than a single point, the intersection point
     * closest to the ray's origin is returned.
     */
    protected ROVector2f findIntersectionPoint(Ray ray, ROVector2f start, ROVector2f end) {
        IntersectionState state = intersector.determineIntersection(
                ray.getStart().getX(),
                ray.getStart().getY(),
                ray.getEnd().getX(),
                ray.getEnd().getY(),
                start.getX(),
                start.getY(),
                end.getX(),
                end.getY());

        if(state instanceof IntersectionState.Intersecting) {
            return state.getPoint();
        } else if(state instanceof IntersectionState.Colinear) {
            if(lineContainsRayStart(ray, start, end)) {
                return ray.getStart();
            }
            return ray.getStart().closest(endpointsWithinRay(ray, start, end));
        }
        return null;
    }

    //assumes ray and endpoints are colinear
    private ROVector2f[] endpointsWithinRay(Ray ray, ROVector2f start, ROVector2f end) {
        ROVector2f[] possibleIntersects = new ROVector2f[2]; 
        if(pointIsWithinRay(start, ray)) {
            possibleIntersects[0] = start;
        }
        if(pointIsWithinRay(end, ray)) {
            possibleIntersects[1] = end;
        }
        return possibleIntersects;
    }

    //assumes ray and point are colinear
    protected boolean pointIsWithinRay(ROVector2f point, Ray ray) {
        return intersector.isPointWithinColinearSegment(point, ray.getStart(), ray.getEnd());
    }

    //assumes line and point are colinear
    private boolean lineContainsRayStart(Ray ray, ROVector2f start, ROVector2f end) {
        return intersector.isPointWithinColinearSegment(ray.getStart(), start, end);
    }
}
{'fraction_non_alphanumeric': 0.09083100708610693, 'fraction_numerical': 0.00622718488297187, 'mean_word_length': 2.419970631424376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1558215', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1273, 'n_words': 339}