# Copyright (c) 2023 Yuki Kimoto
# MIT License

class MyPoint {
  # Interfaces
  interface Stringable;
  interface Cloneable;
  
  # Fields
  has x : ro int;
  has y : ro int;
  
  # Class methods
  static method new : MyPoint ($x : int = 0, $y : int = 0) {
    my $self = new MyPoint;
    
    $self->init($x, $y);
    
    return $self;
  }
  
  # Instance methods
  protected method init : MyPoint ($x : int = 0, $y : int = 0) {
    $self->{x} = $x;
    $self->{y} = $y;
  }
  
  method clear : void () {
    $self->{x} = 0;
    $self->{y} = 0;
  }
  
  method clone : MyPoint () {
    my $self_clone = MyPoint->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;
  }
}
