ch5ex6

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

README

= Exercise 5.6
// Refs:
:url-base: https://github.com/fenegroni/TGPL-exercise-solutions
:workflow: workflows/Exercise 5.6
:action: actions/workflows/ch5ex6.yml
:url-workflow: {url-base}/{workflow}
:url-action: {url-base}/{action}
:badge-exercise: image:{url-workflow}/badge.svg?branch=main[link={url-action}]

{badge-exercise}

Modify the `corner` function in section 3.2 of the book,
to use named results and a bare return statement.

== Test

We rename the previous implementation of `corner` into `oldcorner`.
This allows us to compare the new implementation of `corner` to the old one.

=== `Test_corner`

An opaque-box test of `corner` vs. `oldcorner`.
Given the same input, we expect the same output from both functions.
If `oldcorner` returns NaN, we skip to the next iteration so that
a new Corner implementation can resolve the issue.

=== `TestCornerReturnsNaNOrInf`

Reports for what combinations of i and j
`corner` returns an invalid number (NaN or +/-Inf).
This was an issue with the original implementation
which we fix in Exercise 3.1.

Documentation

Overview

Surface computes an SVG rendering of a 3-D surface function.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Corner

func Corner(i, j int) (sx, sy float64)
Example
fmt.Printf("<svg xmlns='http://www.w3.org/2000/svg' "+
	"style='stroke: grey; fill: white; stroke-width: 0.7' "+
	"width='%d' height='%d'>", width, height)
for i := 0; i < cells; i++ {
	for j := 0; j < cells; j++ {
		ax, ay := Corner(i+1, j)
		bx, by := Corner(i, j)
		cx, cy := Corner(i, j+1)
		dx, dy := Corner(i+1, j+1)
		fmt.Printf("<polygon points='%g,%g %g,%g %g,%g %g,%g'/>\n",
			ax, ay, bx, by, cx, cy, dx, dy)
	}
}
fmt.Println("</svg>")
Output:

func OldCorner

func OldCorner(i, j int) (float64, float64)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL