Difference between revisions of "Render Part C Assignment"
Line 57: | Line 57: | ||
===calculate_local_bounds=== | ===calculate_local_bounds=== | ||
Returns an instance of Bounds specified by min and max instances of <code>Point2</code>. | Returns an instance of Bounds specified by min and max instances of <code>Point2</code>. | ||
+ | |||
+ | [[File:Equilateral triangle bounds.png]] | ||
==BezierCurve, Chord, Image, Text== | ==BezierCurve, Chord, Image, Text== |
Revision as of 17:37, 2 December 2020
In this studio we will evolve our code from Render_Part_B_Assignment to add new methods and a new class.
Continue editing files in the render/assignment directory.
Contents
Code to Implement
Bounds
file: | src/main/ruby/render/assignment/bounds.rb | |
class: | Bounds | |
superclass: | Object | |
methods: | initialize(min,max) min() max() |
Note: min and max should be instances of Point2
.
Note: You may wish to use Ruby's convenient Struct construct.
Transform
file: | src/main/ruby/render/assignment/transform.rb | |
class: | Transform | |
superclass: | Object | |
methods to evolve: | Ø | |
methods to add: | move(direction,amount) calculate_bounds() |
|
methods to remove: | Ø |
move
the move method will accept two parameters: direction and amount.
direction can be one of four symbols
:left :right :up :down
- left corresponds to translating along the negative x axis
- right corresponds to translating along the positive x axis
- down corresponds to translating along the negative y axis
- up corresponds to translating along the positive y axis
any other value for direction should raise an ArgumentError.
calculate_bounds
invoke calculate_local_bounds
and transform the returned bounds by x and y.
NOTE: calculate_local_bounds
is abstract. it must be defined by the subclasses.
Rectangle
file: | src/main/ruby/render/assignment/rectangle.rb | |
class: | Rectangle | |
superclass: | ColorTransform | |
methods to evolve: | Ø | |
methods to add: | calculate_local_bounds | |
methods to remove: | Ø |
calculate_local_bounds
Returns an instance of Bounds specified by min and max instances of Point2
.
Ellipse
file: | src/main/ruby/render/assignment/ellipse.rb | |
class: | Ellipse | |
superclass: | ColorTransform | |
methods to evolve: | Ø | |
methods to add: | calculate_local_bounds | |
methods to remove: | Ø |
calculate_local_bounds
Returns an instance of Bounds specified by min and max instances of Point2
.
EquilateralTriangle
file: | src/main/ruby/render/assignment/equilateral_triangle.rb | |
class: | Rectangle | |
superclass: | EquilateralTriangle | |
methods to evolve: | Ø | |
methods to add: | calculate_local_bounds | |
methods to remove: | Ø |
calculate_local_bounds
Returns an instance of Bounds specified by min and max instances of Point2
.
BezierCurve, Chord, Image, Text
Imagine what it would be like to define calculate_local_bounds
for each of these classes.
CompositeTransform
calculate_local_bounds
Scene
calculate_bounds
ConvexPolygon
render_transformed
calculate_local_bounds
Testing Your Solution
Visual Comparison
file to run: | src/test/ruby/render/part_c/part_c_test_snapshots_web_page_generator.rb |
Unit Test
file: | src/test/ruby/render/part_c/part_c_unit_test.rb | UnitTest |
note: ensure that you have removed all printing to receive credit for any assignment.
file: | src/test/ruby/render/part_c/part_c_move_unit_test.rb | UnitTest |
note: ensure that you have removed all printing to receive credit for any assignment.
file: | src/test/ruby/render/part_c/part_c_bounds_unit_test.rb | UnitTest |
note: ensure that you have removed all printing to receive credit for any assignment.