<commit_before>package com.bhullnatik.gonioview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class GonioView extends View {

    private Paint mHandlePaint;
    private Paint mTextPaint;

    private Point mHandles[];

    private static final float HANDLE_SIZE = 36f;

    private OnAngleSelectedListener mListener = null;

    public GonioView(Context context) {
        super(context);

        initialize();
    }

    public GonioView(Context context, AttributeSet attrs) {
        super(context, attrs);

        initialize();
    }

    private void initialize() {
        int color = Color.BLUE;
        mHandlePaint = new Paint();
        mTextPaint = new Paint();

        mHandlePaint.setColor(color);
        mHandlePaint.setAntiAlias(true);
        mHandlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mHandlePaint.setStrokeWidth(8f);

        mTextPaint.setTextSize(64f);
        mTextPaint.setColor(color);
        mTextPaint.setTextAlign(Paint.Align.CENTER);
        mTextPaint.setAntiAlias(true);

        mHandles = new Point[3];
        // TODO: Setup initial points
        mHandles[0] = new Point(50, 50);
        mHandles[1] = new Point(100, 25);
        mHandles[2] = new Point(100, 75);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawLines(canvas);
        drawHandles(canvas);
        drawAngle(canvas);
    }

    private void drawHandles(Canvas canvas) {
        for (Point handle : mHandles) {
            canvas.drawCircle(handle.x, handle.y, HANDLE_SIZE, mHandlePaint);
        }
    }

    private void drawLines(Canvas canvas) {
        Point middleHandle = mHandles[1];

        canvas.drawLine(mHandles[0].x, mHandles[0].y, middleHandle.x, middleHandle.y, mHandlePaint);
        canvas.drawLine(middleHandle.x, middleHandle.y, mHandles[2].x, mHandles[2].y, mHandlePaint);
    }

    private void drawAngle(Canvas canvas) {
        int x = (mHandles[0].x + mHandles[1].x + mHandles[2].x) / 3;
        int y = (mHandles[0].y + mHandles[1].y + mHandles[2].y) / 3;

        canvas.drawText(getCurrentAngle() + "˚", x, y, mTextPaint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                return onDown(event);
            case MotionEvent.ACTION_MOVE:
                return onMove(event);
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mCurrentHandle = null;
                if (mListener != null) {
                    mListener.onAngleSelected();
                }
                return true;
        }
        return false;
    }

    private Point mCurrentHandle = null;

    private boolean onDown(MotionEvent event) {
        invalidate();
        Point handle = checkIfHandleTouch(event.getX(), event.getY());

        if (handle == null) {
            return false;
        }
        mCurrentHandle = handle;
        return true;
    }

    private boolean onMove(MotionEvent event) {
        invalidate();
        if (mCurrentHandle != null && checkInBounds(event.getX(), event.getY())) {
            mCurrentHandle.set((int) event.getX(), (int) event.getY());
            return true;
        }
        return false;
    }

    private Point checkIfHandleTouch(float x, float y) {
        for (Point handle : mHandles) {
            if (Math.sqrt(Math.pow(x - handle.x, 2) + Math.pow(y - handle.y, 2)) < HANDLE_SIZE) {
                return handle;
            }
        }
        return null;
    }

    private boolean checkInBounds(float x, float y) {
        return (((getLeft() + HANDLE_SIZE / 2) < x && x < getRight() - HANDLE_SIZE / 2) &&
                ((getTop() + HANDLE_SIZE / 2) < y && y < getBottom() - HANDLE_SIZE / 2));
    }

    public int getCurrentAngle() {
        Point AB = new Point(mHandles[1].x - mHandles[0].x, mHandles[1].y - mHandles[0].y);
        Point CB = new Point(mHandles[1].x - mHandles[2].x, mHandles[1].y - mHandles[2].y);

        double dot = (AB.x * CB.x + AB.y * CB.y);
        double cross = (AB.x * CB.y - AB.y * CB.x);

        double alpha = Math.atan2(cross, dot);<commit_msg>Fix size issue<commit_after>package com.bhullnatik.gonioview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class GonioView extends View {

    private Paint mHandlePaint;
    private Paint mTextPaint;

    private Point mHandles[];

    private static final float HANDLE_SIZE = 36f;

    private OnAngleSelectedListener mListener = null;

    public GonioView(Context context) {
        super(context);

        initialize();
    }

    public GonioView(Context context, AttributeSet attrs) {
        super(context, attrs);

        initialize();
    }

    private void initialize() {
        int color = Color.BLUE;
        mHandlePaint = new Paint();
        mTextPaint = new Paint();

        mHandlePaint.setColor(color);
        mHandlePaint.setAntiAlias(true);
        mHandlePaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mHandlePaint.setStrokeWidth(8f);

        mTextPaint.setTextSize(64f);
        mTextPaint.setColor(color);
        mTextPaint.setTextAlign(Paint.Align.CENTER);
        mTextPaint.setAntiAlias(true);

        mHandles = new Point[3];
        // TODO: Setup initial points
        mHandles[0] = new Point(50, 50);
        mHandles[1] = new Point(100, 25);
        mHandles[2] = new Point(100, 75);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawLines(canvas);
        drawHandles(canvas);
        drawAngle(canvas);
    }

    private void drawHandles(Canvas canvas) {
        for (Point handle : mHandles) {
            canvas.drawCircle(handle.x, handle.y, HANDLE_SIZE, mHandlePaint);
        }
    }

    private void drawLines(Canvas canvas) {
        Point middleHandle = mHandles[1];

        canvas.drawLine(mHandles[0].x, mHandles[0].y, middleHandle.x, middleHandle.y, mHandlePaint);
        canvas.drawLine(middleHandle.x, middleHandle.y, mHandles[2].x, mHandles[2].y, mHandlePaint);
    }

    private void drawAngle(Canvas canvas) {
        int x = (mHandles[0].x + mHandles[1].x + mHandles[2].x) / 3;
        int y = (mHandles[0].y + mHandles[1].y + mHandles[2].y) / 3;

        canvas.drawText(getCurrentAngle() + "˚", x, y, mTextPaint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                return onDown(event);
            case MotionEvent.ACTION_MOVE:
                return onMove(event);
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mCurrentHandle = null;
                if (mListener != null) {
                    mListener.onAngleSelected();
                }
                return true;
        }
        return false;
    }

    private Point mCurrentHandle = null;

    private boolean onDown(MotionEvent event) {
        invalidate();
        Point handle = checkIfHandleTouch(event.getX(), event.getY());

        if (handle == null) {
            return false;
        }
        mCurrentHandle = handle;
        return true;
    }

    private boolean onMove(MotionEvent event) {
        invalidate();
        if (mCurrentHandle != null && checkInBounds(event.getX(), event.getY())) {
            mCurrentHandle.set((int) event.getX(), (int) event.getY());
            return true;
        }
        return false;
    }

    private Point checkIfHandleTouch(float x, float y) {
        for (Point handle : mHandles) {
            if (Math.sqrt(Math.pow(x - handle.x, 2) + Math.pow(y - handle.y, 2)) < HANDLE_SIZE) {
                return handle;
            }
        }
        return null;
    }

    private boolean checkInBounds(float x, float y) {
        return ((HANDLE_SIZE / 2 < x && x < getRight() - HANDLE_SIZE / 2) &&
                (HANDLE_SIZE / 2 < y && y < getBottom() - HANDLE_SIZE / 2));
    }

    public int getCurrentAngle() {
        Point AB = new Point(mHandles[1].x - mHandles[0].x, mHandles[1].y - mHandles[0].y);
        Point CB = new Point(mHandles[1].x - mHandles[2].x, mHandles[1].y - mHandles[2].y);

        double dot = (AB.x * CB.x + AB.y * CB.y);
        double cross = (AB.x * CB.y - AB.y * CB.x);

        double alpha = Math.atan2(cross, dot);
{'fraction_non_alphanumeric': 0.11719282307517602, 'fraction_numerical': 0.011583011583011582, 'mean_word_length': 2.217756667884545, 'pattern_counts': {'":': 0, '<': 13, '<?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': '5525833', 'n_tokens_mistral': 2807, 'n_tokens_neox': 2666, 'n_words': 599}