import java.awt.*;
import java.util.*;

// class MPoint - the most basic MMoveable
//
//
// Author:      Alexander Bogomolny, CTK Software, Inc.
// URL:         http://www.cut-the-knot.com
// Date:        November 30, 2000
// Copyright:   A. Bogomolny
//              Permission to use and modify the file is therefore granted
//              as long as this comment remains unchanged. Do this at your
//              own risk.
//
class MPoint extends Point implements MMoveable
{
    // when the cursor selects a moveable
    // it must not be exactly at the location
    // of the latter but some distance away.
    // For a motion to be smooth, however,
    // location of the moveable must be changed
    // smoothly. m_Defect stores the vector from
    // the cursor to the location
    Point Defect;

    // sometimes it's desirable
    // to indicate the location
    // by a small circle
    boolean Drawable = false;
    public void SetDrawable(boolean set) { Drawable = set; }

    // MPoint is draggable by default.
    // Sometimes it's desirable to switch
    // this feature off
    boolean Draggable;
    public void SetDraggable(boolean set) { Draggable = set; }

    // MMoveable is indicated by a circle.
    // Sometimes there is a need to hide it.
    //
    boolean ShowCircle = true;
    public void ShowCircle(boolean show) { ShowCircle = show; }

    int    R = 2;   // radius of the circle
    public void SetRadius(int r) { R = r; }

    Color  FColor;  // color of the circle
    public void SetColor(Color color) { FColor = color; }

    int epsilon = 10;
    public void SetAccuracy(int a) { epsilon = a; }

    // Moving = being dragged
    //
    boolean Moving;
    public void SetMoving(boolean set) { Moving = set; }

    public MPoint(int a, int b)
    {
        super(a, b);

        FColor = Color.black;
        R = 1;
        Defect = new Point(0, 0);
    }

    public MPoint(Point p)
    {
        this(p.x, p.y);
    }

    public boolean IsHit(int a, int b)
    {
        Defect.x = x - a;
        Defect.y = y - b;

        return (Defect.x*Defect.x + Defect.y*Defect.y < epsilon);
    }

    public boolean IsHit(Point p)
    {
        return IsHit(p.x, p.y);
    }

    public void UpdateLocation(int a, int b)
    {
        x = Defect.x + a;
        y = Defect.y + b;
    }

    public void Draw(Graphics g)
    {
        if (ShowCircle)
        {
            g.setColor(FColor);
            g.drawOval(x - R, y - R, 2*R+1, 2*R+1);
        }
    }

    public void DrawBackground(Graphics g)
    {
        if (ShowCircle)
        {
            g.setColor(FColor);
            g.fillOval(x - R, y - R, 2*R+1, 2*R+1);
        }
    }

    public void DrawFrame(Graphics g)
    {
        Draw(g);
    }

    public boolean Inside(int a, int b)
    {
        return IsHit(a,b);
    }
}