Skip to content

Commit f0c4268

Browse files
RuboCop and YARD actions now run automatically. Docs are complete and updated.
* Fix duplicate yard requirement * Generate new YARD docs * remove erronious doc folder * create gitignore file * remove logs and exceptions folders * Remove YARD. Again. * Generate new YARD docs * try to fix YARD breaking * combine YARD and RuboCop into one action * trying to manually run rubocop * fix rubocop causing a fail * Generate new YARD docs * Document Circle code update rubocop.yml * Generate new YARD docs * document circle_raster * Generate new YARD docs * document point_inside_triangle improve documentation verbage * Generate new YARD docs * improve documentation verbage * Generate new YARD docs * Improve YARD type names * Generate new YARD docs * document triangle_outline * Generate new YARD docs * document point_at_distance_angle * Generate new YARD docs * fix point_inside_triangle doc * Generate new YARD docs * fix broken inline code blocks * Generate new YARD docs * Create more inline code blocks * Generate new YARD docs * fix missing code block * Generate new YARD docs * Document remaining methods * Generate new YARD docs * Add missing description for triangle_raster some minor formatting changes * Generate new YARD docs * Fix typos * Generate new YARD docs * Fix Typos * Generate new YARD docs * Change module description * Generate new YARD docs * Change github actions commit message * Run RuboCop Linter and update YARD docs * Run RuboCop Linter and update YARD docs Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 82708c0 commit f0c4268

38 files changed

+1643
-4087
lines changed

.github/workflows/yard.yml .github/workflows/post-processing.yml

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# .github/workflows/rubocop.yml
1+
# .github/workflows/post-processing.yml
22

3-
name: YARD
3+
name: Post-Processing
44

55
on: [push, pull_request]
66

@@ -14,20 +14,12 @@ jobs:
1414
uses: actions/setup-ruby@v1
1515
with:
1616
ruby-version: 3.0.2 # Replace with your ruby version
17-
- name: Gems Cache
18-
id: gem-cache
19-
uses: actions/cache@v1
20-
with:
21-
path: vendor/bundle
22-
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
23-
restore-keys: |
24-
${{ runner.os }}-gem-
25-
- name: Add YARD
26-
run: bundle add yard
27-
- name: Install
17+
- name: Install Gems
2818
run: bundle install
19+
- name: RuboCop Linter Action
20+
run: rubocop -a --fail-level error
2921
- name: Run Yard
30-
run: yard doc -m markdown -o docs --exclude app/main.rb
22+
run: yard doc -m markdown -o docs --exclude app/main.rb
3123
- uses: EndBug/add-and-commit@v7 # You can change this to use a specific version.
3224
with:
3325
# The arguments for the `git add` command (see the paragraph below for more info)
@@ -55,7 +47,7 @@ jobs:
5547

5648
# The message for the commit.
5749
# Default: 'Commit from GitHub Actions (name of the workflow)'
58-
message: 'Generate new YARD docs'
50+
message: 'Run RuboCop Linter and update YARD docs'
5951

6052
# The way the action should handle pathspec errors from the add and remove commands. Three options are available:
6153
# - ignore -> errors will be logged but the step won't fail

.github/workflows/rubocop.yml

-28
This file was deleted.

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ AllCops:
33
- 'app/main.rb'
44
- Gemfile
55
- Gemfile.lock
6+
NewCops: enable
67

78
Layout/LineLength:
89
Max: 150

.yardoc/checksums

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
app/lib/dinraal.rb e9fb7ef8f9f578b857e2aaa1f50011118a36f878
1+
app/lib/dinraal.rb a5174190d9dec7c363f3bf88d0a5b38aa5e11376

.yardoc/objects/root.dat

10.3 KB
Binary file not shown.

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# dinraal
22

3-
[![Ruby - Rubocop](https://github.com/DSchaedler/dinraal/actions/workflows/rubocop.yml/badge.svg)](https://github.com/DSchaedler/dinraal/actions/workflows/rubocop.yml)[![YARD](https://github.com/DSchaedler/dinraal/actions/workflows/yard.yml/badge.svg)](https://github.com/DSchaedler/dinraal/actions/workflows/yard.yml)
3+
[![Post-Processing](https://github.com/DSchaedler/dinraal/actions/workflows/post-processing.yml/badge.svg)](https://github.com/DSchaedler/dinraal/actions/workflows/post-proecessing.yml)
44

55
Dinraal is a library for working with shapes in DragonRuby Game Toolkit. By default, DRGTK does not support rendering or working with any shapes outside of rectangles. Until now, other shapes have been provided by sprites.
66

@@ -50,6 +50,9 @@ Triangles are defined as a hash of points, with any additional information.
5050
- Speed improvements to the `triangle_raster` and `circle_raster` methods
5151
- Vector calculations for area over Heron's Formula
5252

53+
## YARD
54+
When documenting with YARD, use the full variable / object type names found here https://rubydoc.info/gems/yard/0.9.26/YARD/CodeObjects#BUILTIN_ALL-constant
55+
5356
# About Dinraal
5457
Dinraal is created by Dee Schaedler. Many thanks to the DragonRuby Discord server for inspiration and feedback. https://discord.dragonruby.org
5558

app/lib/dinraal.rb

+102-20
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# frozen_string_literal: true
22

3-
# Module provides some Triangle generation and manipulation methods to DragonRuby Game Toolkit.
3+
# Module provides methods for manipulating shapes to DragonRuby Game Toolkit.
44
# By D Schaedler. Released under MIT License.
55
# https://github.com/DSchaedler/dinraal
66
module Dinraal
7-
# Calculates a `border` `rect` for the bounding box of the provided triangle
7+
# Calculates a `border` for the bounding box of the given `triangle`.
88
#
99
# @param options [Hash]
10-
# @option options x [Float] Point 1 x position.
11-
# @option options y [Float] Point 1 x position.
12-
# @option options x2 [Float] Point 2 x position.
13-
# @option options y2 [Float] Point 2 x position.
14-
# @option options x3 [Float] Point 3 x position.
15-
# @option options y3 [Float] Point 3 x position.
10+
# @option options x [Float] Vertex 1 x position.
11+
# @option options y [Float] Vertex 1 y position.
12+
# @option options x2 [Float] Vertex 2 x position.
13+
# @option options y2 [Float] Vertex 2 y position.
14+
# @option options x3 [Float] Vertex 3 x position.
15+
# @option options y3 [Float] Vertex 3 y position.
1616
#
17-
# @return [Hash] A DR `border` hash. E.g. `{x: 100, y: 150, w: 300, h: 400}.border!`
17+
# @return [Hash] A DR `border` hash.
1818
def triangle_bounding_box(options = {})
1919
x = options[:x]
2020
y = options[:y]
@@ -32,17 +32,17 @@ def triangle_bounding_box(options = {})
3232
{ x: x_min, y: y_min, w: x_max - x_min, h: y_max - y_min }.border!
3333
end
3434

35-
# Calculates the center `point` of the provided triangle
35+
# Calculates the center `point` of the given `triangle`.
3636
#
3737
# @param options [Hash]
38-
# @option options x [Float] Point 1 x position.
39-
# @option options y [Float] Point 1 x position.
40-
# @option options x2 [Float] Point 2 x position.
41-
# @option options y2 [Float] Point 2 x position.
42-
# @option options x3 [Float] Point 3 x position.
43-
# @option options y3 [Float] Point 3 x position.
38+
# @option options x [Float] Vertex 1 x position.
39+
# @option options y [Float] Vertex 1 y position.
40+
# @option options x2 [Float] Vertex 2 x position.
41+
# @option options y2 [Float] Vertex 2 y position.
42+
# @option options x3 [Float] Vertex 3 x position.
43+
# @option options y3 [Float] Vertex 3 y position.
4444
#
45-
# @return [Hash] A DR `point` hash. E.g. `{x: 20, y: 45}`
45+
# @return [Hash] A DR `point` hash.
4646
def triangle_center(options = {})
4747
x = options[:x]
4848
y = options[:y]
@@ -54,6 +54,18 @@ def triangle_center(options = {})
5454
{ x: ((x + x2 + x3) / 3).to_i, y: ((y + y2 + y3) / 3).to_i }
5555
end
5656

57+
# Creates the outline of a `circle` .
58+
#
59+
# @param options [Hash]
60+
# @option options x [Float] Center x position.
61+
# @option options y [Float] Center y position.
62+
# @option options radius [Float] Radius of the `circle` .
63+
# @option options r [Integer] Color red value.
64+
# @option options g [Integer] Color blue value.
65+
# @option options b [Integer] Color green value.
66+
# @option options a [Integer] Color alpha value.
67+
#
68+
# @return [Array] An array of `solids` in hash notation.
5769
def circle_outline(options = {})
5870
x = options[:x]
5971
y = options[:y]
@@ -85,6 +97,18 @@ def circle_outline(options = {})
8597
pixels
8698
end
8799

100+
# Create a filled `circle` using raster method.
101+
#
102+
# @param options [Hash]
103+
# @option options x [Float] Center x position.
104+
# @option options y [Float] Center y position.
105+
# @option options radius [Float] Radius of the `circle``.
106+
# @option options r [Integer] Color red value.
107+
# @option options g [Integer] Color blue value.
108+
# @option options b [Integer] Color green value.
109+
# @option options a [Integer] Color alpha value.
110+
#
111+
# @return [Array] An array of `solids` in hash notation.
88112
def circle_raster(options = {})
89113
args = $gtk.args
90114

@@ -119,6 +143,12 @@ def circle_raster(options = {})
119143
pixels
120144
end
121145

146+
# Determines if the given `point` is in the given `triangle`.
147+
#
148+
# @param point [Hash] `point` in DR hash notation.
149+
# @param triangle [Hash] `triangle` in Dinraal hash notation.
150+
#
151+
# @return [Boolean] `true` or `false`
122152
def point_inside_triangle?(point:, triangle:)
123153
args = $gtk.args
124154

@@ -139,23 +169,38 @@ def point_inside_triangle?(point:, triangle:)
139169
leg0_slope = args.geometry.line_slope(leg0.flatten, replace_infinity: 1080)
140170
leg0_intercept = triangle[0][1] - (leg0_slope * triangle[0][0])
141171

142-
return false unless point_y <= leg0_slope * point_x + leg0_intercept
172+
return false unless point_y <= (leg0_slope * point_x) + leg0_intercept
143173

144174
leg1 = [triangle[0], triangle[2]]
145175
leg1_slope = args.geometry.line_slope(leg1.flatten, replace_infinity: 1080)
146176
leg1_intercept = triangle[0][1] - (leg1_slope * triangle[0][0])
147177

148-
return false unless point_y <= leg1_slope * point_x + leg1_intercept
178+
return false unless point_y <= (leg1_slope * point_x) + leg1_intercept
149179

150180
leg2 = [triangle[1], triangle[2]]
151181
leg2_slope = args.geometry.line_slope(leg2.flatten, replace_infinity: 1080)
152182
leg2_intercept = triangle[2][1] - (leg2_slope * triangle[2][0])
153183

154-
return false unless point_y >= leg2_slope * point_x + leg2_intercept
184+
return false unless point_y >= (leg2_slope * point_x) + leg2_intercept
155185

156186
true
157187
end
158188

189+
# Creates the outline of a `triangle`.
190+
#
191+
# @param options [Hash]
192+
# @option options x [Float] Vertex 1 x position.
193+
# @option options y [Float] Vertex 1 y position.
194+
# @option options x2 [Float] Vertex 2 x position.
195+
# @option options y2 [Float] Vertex 2 y position.
196+
# @option options x3 [Float] Vertex 3 x position.
197+
# @option options y3 [Float] Vertex 3 y position.
198+
# @option options r [Integer] Color red value.
199+
# @option options g [Integer] Color blue value.
200+
# @option options b [Integer] Color green value.
201+
# @option options a [Integer] Color alpha value.
202+
#
203+
# @return [Array] An array of `solids` in hash notation.
159204
def triangle_outline(options = {})
160205
x = options[:x]
161206
y = options[:y]
@@ -175,6 +220,14 @@ def triangle_outline(options = {})
175220
lines
176221
end
177222

223+
# Calculates a new `point` given a starting `point`, distance, and angle.
224+
#
225+
# @param options [Hash]
226+
# @option options point [Hash] `point` in DR hash notation.
227+
# @option options distance [Float] Distance between the given and generated point.
228+
# @option options angle [Float] Angle from given `point` to generated `point` in degrees.
229+
#
230+
# @return [Hash] `point` in DR hash notation.
178231
def point_at_distance_angle(options = {})
179232
point = options[:point]
180233
distance = options[:distance]
@@ -187,6 +240,23 @@ def point_at_distance_angle(options = {})
187240
new_point
188241
end
189242

243+
# Creates a filled `triangle` using the raster method.
244+
#
245+
# @param options [Hash]
246+
# @option options x [Float] Vertex 1 x position.
247+
# @option options y [Float] Vertex 1 y position.
248+
# @option options x2 [Float] Vertex 2 x position.
249+
# @option options y2 [Float] Vertex 2 y position.
250+
# @option options x3 [Float] Vertex 3 x position.
251+
# @option options y3 [Float] Vertex 3 y position.
252+
# @option options r [Integer] Optional. Color red value. Defaults to `0`.
253+
# @option options g [Integer] Optional. Color blue value. Defaults to `0`.
254+
# @option options b [Integer] Optional. Color green value. Defaults to `0`.
255+
# @option options a [Integer] Optional. Color alpha value. Defaults to `255`.
256+
# @option options path [String] Optional. Image path. Defaults to `'pixel'`.
257+
# @option options image_width [Float] Optional. Image width. Defaults to `triangle` width.
258+
#
259+
# @return [Array] An array of `solids` in hash notation.
190260
def triangle_raster(options = {})
191261
x = options[:x]
192262
y = options[:y]
@@ -293,6 +363,12 @@ def triangle_raster(options = {})
293363
raster_lines
294364
end
295365

366+
# Determines if the given `rect` is inside of the given `triangle`.
367+
#
368+
# @param rectangle [Hash] `rect` in DR hash notation.
369+
# @param triangle [Hash] `triangle` in Dinraal hash notation.
370+
#
371+
# @return [Boolean] `true` or `false`
296372
def rectangle_inside_triangle?(rectangle:, triangle:)
297373
return false unless point_inside_triangle?(point: { x: rectangle[:x], y: rectangle[:y] }, triangle: triangle)
298374

@@ -305,6 +381,12 @@ def rectangle_inside_triangle?(rectangle:, triangle:)
305381
true
306382
end
307383

384+
# Determines if the `inner` `triangle` is contained by the `outer` `triangle`.
385+
#
386+
# @param inner [Hash] `triangle` in Dinraal hash notation.
387+
# @param outer [Hash] `triangle` in Dinraal hash notation.
388+
#
389+
# @return [Boolean] `true` or `false`
308390
def triangle_inside_triangle?(inner:, outer:)
309391
# Return true if tri1 is contained by tri2
310392
return false unless point_inside_triangle?(point: { x: inner[:x], y: inner[:y] }, triangle: outer)

0 commit comments

Comments
 (0)