Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point {
- has int $.x;
- has int $.y;
- method new( int $x, int $y ) {
- return self.bless( :$x, :$y );
- }
- method is-close( Point $other, Numeric $close = 5 ) returns Bool {
- return ($.x - $other.x)**2 + ($.y - $other.y)**2 < $close;
- }
- }
- class Line {
- has Point $.p1;
- has Point $.p2;
- has Bool $.is-short;
- method new( Point $p1, Point $p2 ) {
- return self.bless( :$p1, :$p2 );
- }
- submethod BUILD() {
- $!is-short = $!p1.is-close( $!p2 );
- }
- }
- my $p1 = Point.new(1,2);
- my $p2 = Point.new(2,3);
- say $p1.is-close($p2);
- my $line = Line.new( $p1, $p2 );
- say $line.is-short;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement