Skip to content

Commit 83f69dd

Browse files
committed
Update the sample problem demonstrating custom graphtool checker ussage.
1 parent 1ea544f commit 83f69dd

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

tutorial/sample-problems/Algebra/GraphToolCustomChecker.pg

+9-19
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,6 @@ $gt = GraphTool("{circle, solid, ($h, $k), ($h + $r, $k)}")->with(
8686
my @errors;
8787
my $count = 1;
8888

89-
# Get the center and point that define the correct circle and
90-
# compute the square of the radius.
91-
my ($cx, $cy) = $correct->[0]->extract(3)->value;
92-
my ($px, $py) = $correct->[0]->extract(4)->value;
93-
my $r_squared = ($cx - $px)**2 + ($cy - $py)**2;
94-
95-
my $pointOnCircle = sub {
96-
my $point = shift;
97-
my ($x, $y) = $point->value;
98-
return ($x - $cx)**2 + ($y - $cy)**2 == $r_squared;
99-
};
100-
10189
# Iterate through the objects the student graphed and check to
10290
# see if each is the correct circle.
10391
for (@$student) {
@@ -107,12 +95,8 @@ $gt = GraphTool("{circle, solid, ($h, $k), ($h + $r, $k)}")->with(
10795
# type as the correct object type (a circle in this case),
10896
# has the same solid or dashed status, has the same center, and
10997
# if the other point graphed is on the circle.
110-
if ($_->extract(1) eq $correct->[0]->extract(1)
111-
&& $_->extract(2) eq $correct->[0]->extract(2)
112-
&& $_->extract(3) == $correct->[0]->extract(3)
113-
&& $pointOnCircle->($_->extract(4)))
114-
{
115-
$score += 1;
98+
if ($correct->[0] == $_) {
99+
++$score;
116100
next;
117101
}
118102

@@ -124,7 +108,13 @@ $gt = GraphTool("{circle, solid, ($h, $k), ($h + $r, $k)}")->with(
124108
next;
125109
}
126110

127-
if ($_->extract(2) ne $correct->[0]->extract(2)) {
111+
# Calling $correct->[0]->cmp($_, 1) does a "fuzzy" comparison.
112+
# This is the same as $correct->[0] == $_ except that it ignores
113+
# the solid or dashed status and only checks the center point
114+
# and radius, i.e., that the circles are the same.
115+
if ($correct->[0]->cmp($_, 1)
116+
&& $_->extract(2) ne $correct->[0]->extract(2))
117+
{
128118
push(@errors,
129119
"The $nth object graphed should be a "
130120
. $correct->[0]->extract(2)

0 commit comments

Comments
 (0)