# Copyright (c) 2023 Yuki Kimoto
# MIT License

class Point {
  # Interfaces
  interface Stringable;
  interface Cloneable;
  
  # Fields
  has x : rw protected int;
  has y : rw protected int;
  
  # Class methods
  static method new : Point ($x = 0 : int, $y = 0 : int) {
    my $self = new Point;
    
    $self->init($x, $y);
    
    return $self;
  }
  
  # Instance methods
  protected method init : Point ($x = 0 : int, $y = 0 : int) {
    $self->{x} = $x;
    $self->{y} = $y;
  }
  
  method clear : void () {
    $self->{x} = 0;
    $self->{y} = 0;
  }
  
  method clone : Point () {
    my $self_clone = Point->new($self->x, $self->y);
    
    return $self_clone;
  }
  
  method to_string : string () {
    my $x = $self->x;
    my $y = $self->y;
    
    my $string = "($x,$y)";
    
    return $string;
  }
}