Skip to content

Commit

Permalink
Merge pull request #415 from yob/strict-typed-new-classes
Browse files Browse the repository at this point in the history
Change two recently added classes to strict typing
  • Loading branch information
yob authored Dec 29, 2021
2 parents bf78e6e + 3e17bf5 commit 82a4b96
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pdf/reader/point.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
# typed: true
# typed: strict
# frozen_string_literal: true

module PDF
Expand Down
4 changes: 2 additions & 2 deletions lib/pdf/reader/rectangle.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
# typed: true
# typed: strict
# frozen_string_literal: true

module PDF
Expand Down Expand Up @@ -85,7 +85,7 @@ def apply_rotation(degrees)
new_x2 = bottom_left.x
new_y2 = bottom_left.y + width
end
set_corners(new_x1, new_y1, new_x2, new_y2)
set_corners(new_x1 || 0, new_y1 || 0, new_x2 || 0, new_y2 || 0)
end

private
Expand Down
23 changes: 21 additions & 2 deletions rbi/pdf-reader.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,10 @@ module PDF
y: Numeric,
).void
end
def initialize(x, y); end
def initialize(x, y)
@x = T.let(0, Numeric)
@y = T.let(0, Numeric)
end

sig { returns(Numeric) }
def x; end
Expand Down Expand Up @@ -1138,6 +1141,7 @@ module PDF
end

class Rectangle

sig { params(arr: T::Array[Numeric]).returns(PDF::Reader::Rectangle) }
def self.from_array(arr); end

Expand All @@ -1149,7 +1153,13 @@ module PDF
y2: Numeric
).void
end
def initialize(x1, y1, x2, y2); end

def initialize(x1, y1, x2, y2)
@bottom_left = T.let(PDF::Reader::Point.new(0,0), PDF::Reader::Point)
@bottom_right = T.let(PDF::Reader::Point.new(0,0), PDF::Reader::Point)
@top_left = T.let(PDF::Reader::Point.new(0,0), PDF::Reader::Point)
@top_right = T.let(PDF::Reader::Point.new(0,0), PDF::Reader::Point)
end

sig { returns(PDF::Reader::Point) }
def bottom_left; end
Expand All @@ -1174,6 +1184,15 @@ module PDF

sig { params(degrees: Integer).void }
def apply_rotation(degrees); end

sig { params(point: PDF::Reader::Point).void }
def contains?(point); end

sig { params(other: PDF::Reader::Rectangle).void }
def ==(other); end

sig { params(x1: Numeric, y1: Numeric, x2: Numeric, y2: Numeric).void }
def set_corners(x1, y1, x2, y2); end
end

class Reference
Expand Down

0 comments on commit 82a4b96

Please sign in to comment.