Skip to content

Commit

Permalink
Tweak current-point() method #26
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Dec 8, 2024
1 parent c16aa22 commit 8a7cfe9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/PDF/Content/Ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ return all current graphics state variables
### method current-point

```raku
method current-point() returns PDF::Content::Ops::Vector
method current-point() returns List
```

return current point

This method is only valid in a path context
This method returns the x,y position of current point in a path context, or an empty list otherwise

### multi method op

Expand Down
6 changes: 3 additions & 3 deletions lib/PDF/Content/Ops.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,11 @@ method is-graphics-op($op-name) {

my subset Vector of List is export(:Vector) where {.elems == 2 && .&are ~~ Numeric}
#| return current point
method current-point is rw returns Vector {
method current-point is rw returns List {
sub FETCH($) {
$!context == Path
?? ($!cur-x, $!cur-y)
!! (Numeric, Numeric)
!! ()
}
sub STORE($, Vector \v) {
unless $!context == Path && $!cur-x =~= v[0] && $!cur-x =~= v[1] {
Expand All @@ -894,7 +894,7 @@ method current-point is rw returns Vector {
}
Proxy.new: :&FETCH, :&STORE;
}
=para This method is only valid in a path context
=para This method returns the x,y position of current point in a path context, or an empty list otherwise
#| process operator quarantined by PDF::Grammar::Content / PDF::Native::COS as either an
#| unknown operator or having an incorrect argument list
Expand Down
6 changes: 4 additions & 2 deletions t/current-point.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use Test;
use PDF::Grammar::Test :&is-json-equiv;
plan 8;
plan 10;

use lib 't';
use PDFTiny;
Expand All @@ -26,9 +26,11 @@ given $pdf.add-page.gfx {

.ClosePath;
is-deeply .current-point, (40, 42);
ok .current-point;

.Stroke;
is-deeply .current-point, (Numeric, Numeric);
is-deeply .current-point, List;
nok .current-point;
}

done-testing;

0 comments on commit 8a7cfe9

Please sign in to comment.