Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Skymap::Catalog::ConstellationNames` gives the English name of each of the
88 IAU constellations

### Changed

- `Skymap::Canvas` raises an `ArgumentError` when the padding is negative or
leaves no room for the sky

### Fixed

- The catalogs give an enumerator when `each` is called without a block,
instead of raising a `LocalJumpError`

## [0.2.0] - 2026-10-27

### Added
Expand Down
9 changes: 9 additions & 0 deletions lib/skymap/canvas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

module Skymap
Canvas = Data.define(:size, :padding) do
def initialize(size:, padding:)
unless padding >= 0 && padding < size / 2.0
raise ArgumentError,
"padding must not be negative and must be less than half the size"
end

super
end

def center
Point.new(x: size / 2.0, y: size / 2.0)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/skymap/catalog/constellation_boundaries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ConstellationBoundaries
)

def each
return enum_for(:each) unless block_given?

CSV.foreach(PATH, headers: true).chunk_while do |previous, row|
previous["border"] == row["border"]
end.each do |rows|
Expand Down
2 changes: 2 additions & 0 deletions lib/skymap/catalog/constellation_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ConstellationLines
)

def each
return enum_for(:each) unless block_given?

CSV.foreach(PATH, headers: true) do |row|
yield line_from(row)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/skymap/catalog/stars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Stars
PATH = File.expand_path("../../../data/stars.csv", __dir__)

def each
return enum_for(:each) unless block_given?

CSV.foreach(PATH, headers: true) do |row|
yield star_from(row)
end
Expand Down
18 changes: 18 additions & 0 deletions spec/skymap/canvas_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# frozen_string_literal: true

RSpec.describe Skymap::Canvas do
describe ".new" do
it "accepts no padding" do
canvas = described_class.new(size: 400, padding: 0)

expect(canvas.radius).to eq(200)
end

it "rejects a negative padding" do
expect { described_class.new(size: 400, padding: -1) }
.to raise_error(ArgumentError, /padding/)
end

it "rejects a padding that leaves no room for the sky" do
expect { described_class.new(size: 400, padding: 200) }
.to raise_error(ArgumentError, /padding/)
end
end

describe "#center" do
it "is the middle of the canvas" do
canvas = described_class.new(size: 400, padding: 1.5)
Expand Down
8 changes: 8 additions & 0 deletions spec/skymap/catalog/constellation_boundaries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
expect(count).to eq(266)
end

it "gives an enumerator without a block" do
catalog = described_class.new

first = catalog.each.next

expect(first).to be_a(Skymap::ConstellationBoundary)
end

it "reads the two constellations a border separates" do
catalog = described_class.new

Expand Down
8 changes: 8 additions & 0 deletions spec/skymap/catalog/constellation_lines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
expect(count).to eq(752)
end

it "gives an enumerator without a block" do
catalog = described_class.new

first = catalog.each.next

expect(first).to be_a(Skymap::ConstellationLine)
end

it "reads the constellation, ends and weight of each line" do
catalog = described_class.new

Expand Down
8 changes: 8 additions & 0 deletions spec/skymap/catalog/stars_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
expect(count).to eq(9096)
end

it "gives an enumerator without a block" do
catalog = described_class.new

first = catalog.each.next

expect(first.hr).to eq(1)
end

it "reads the identifier, J2000 coordinates and magnitude of each star" do
catalog = described_class.new

Expand Down
Loading