/usr/share/axiom-20170501/src/algebra/DRAWCURV.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | )abbrev package DRAWCURV TopLevelDrawFunctionsForAlgebraicCurves
++ Author: Clifton J. Williamson, Jon Steinbach
++ Date Created: 26 June 1990
++ Date Last Updated: October 1991
++ Description:
++ TopLevelDrawFunctionsForAlgebraicCurves provides top level
++ functions for drawing non-singular algebraic curves.
TopLevelDrawFunctionsForAlgebraicCurves(R,Ex) : SIG == CODE where
R : Join(IntegralDomain, OrderedSet, RetractableTo Integer)
Ex : FunctionSpace(R)
ANY1 ==> AnyFunctions1
DROP ==> DrawOption
EQ ==> Equation
F ==> Float
FRAC ==> Fraction
I ==> Integer
L ==> List
P ==> Polynomial
RN ==> Fraction Integer
SEG ==> Segment
SY ==> Symbol
VIEW2 ==> TwoDimensionalViewport
SIG ==> with
draw : (EQ Ex,SY,SY,L DROP) -> VIEW2
++ draw(f(x,y) = g(x,y),x,y,l) draws the graph of a polynomial
++ equation. The list l of draw options must specify a region
++ in the plane in which the curve is to sketched.
CODE ==> add
import ViewportPackage
import PlaneAlgebraicCurvePlot
import ViewDefaultsPackage
import GraphicsDefaults
import DrawOptionFunctions0
import SegmentFunctions2(RN,F)
import SegmentFunctions2(F,RN)
import AnyFunctions1(L SEG RN)
drawToScaleRanges: (SEG F,SEG F) -> L SEG F
drawToScaleRanges(xVals,yVals) ==
-- warning: assumes window is square
xHi := hi xVals; xLo := lo xVals
yHi := hi yVals; yLo := lo yVals
xDiff := xHi - xLo; yDiff := yHi - yLo
pad := abs(yDiff - xDiff)/2
yDiff > xDiff =>
[segment(xLo - pad,xHi + pad),yVals]
[xVals,segment(yLo - pad,yHi + pad)]
intConvert: R -> I
intConvert r ==
(nn := retractIfCan(r)@Union(I,"failed")) case "failed" =>
error "draw: polynomial must have rational coefficients"
nn :: I
polyEquation: EQ Ex -> P I
polyEquation eq ==
ff := lhs(eq) - rhs(eq)
(r := retractIfCan(ff)@Union(FRAC P R,"failed")) case "failed" =>
error "draw: not a polynomial equation"
rat := r :: FRAC P R
retractIfCan(denom rat)@Union(R,"failed") case "failed" =>
error "draw: non-constant denominator"
map(intConvert,numer rat)$PolynomialFunctions2(R,I)
draw(eq,x,y,l) ==
-- obtain polynomial equation
p := polyEquation eq
-- extract ranges from option list
floatRange := option(l,"rangeFloat" :: Symbol)
ratRange := option(l,"rangeRat" :: Symbol)
(floatRange case "failed") and (ratRange case "failed") =>
error "draw: you must specify ranges for an implicit plot"
ranges : L SEG RN := nil() -- dummy value
floatRanges : L SEG F := nil() -- dummy value
xRange : SEG RN := segment(0,0) -- dummy value
yRange : SEG RN := segment(0,0) -- dummy value
xRangeFloat : SEG F := segment(0,0) -- dummy value
yRangeFloat : SEG F := segment(0,0) -- dummy value
if not ratRange case "failed" then
ranges := retract(ratRange :: Any)$ANY1(L SEG RN)
not size?(ranges,2) => error "draw: you must specify two ranges"
xRange := first ranges; yRange := second ranges
xRangeFloat := map((s:RN):F+->convert(s)@Float,xRange)@(SEG F)
yRangeFloat := map((s:RN):F+->convert(s)@Float,yRange)@(SEG F)
floatRanges := [xRangeFloat,yRangeFloat]
else
floatRanges := retract(floatRange :: Any)$ANY1(L SEG F)
not size?(floatRanges,2) =>
error "draw: you must specify two ranges"
xRangeFloat := first floatRanges
yRangeFloat := second floatRanges
xRange := map((s:F):RN+->retract(s)@RN,xRangeFloat)@(SEG RN)
yRange := map((s:F):RN+->retract(s)@RN,yRangeFloat)@(SEG RN)
ranges := [xRange,yRange]
-- create curve plot
acplot := makeSketch(p,x,y,xRange,yRange)
-- process scaling information
if toScale(l,drawToScale()) then
scaledRanges := drawToScaleRanges(xRangeFloat,yRangeFloat)
-- add scaled ranges to list of options
l := concat(ranges scaledRanges,l)
else
-- add ranges to list of options
l := concat(ranges floatRanges,l)
-- process color information
ptCol := pointColorPalette(l,pointColorDefault())
crCol := curveColorPalette(l,lineColorDefault())
-- draw
drawCurves(listBranches acplot,ptCol,crCol,pointSizeDefault(),l)
|