Skip to content

Commit

Permalink
Allow real functions to render
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Aug 6, 2022
1 parent b2fb73d commit 5bd5ed1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions build/mathcell.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ function colorFromHue( h ) {

function colorFromArg( x ) {

if ( !( typeof x === 'object' && 're' in x ) ) // from Math
x = { re: x, im: 0 };

var h = Math.atan2( x.im, x.re ) / Math.PI / 2;

return colorFromHue(h);
Expand Down Expand Up @@ -1879,7 +1882,9 @@ function parametric( vector, xRange, yRange, options={} ) {
var x = xRange[0] + j * xStep;
var v = vector(x,y);

if ( 'complexFunction' in options )
if ( 'complexFunction' in options ) {
if ( !( typeof v[2] === 'object' && 're' in v[2] ) ) // from Math
v[2] = { re: v[2], im: 0 };
switch( options.complexFunction ) {
case 're':
vertices.push( [ v[0], v[1], v[2].re ] );
Expand All @@ -1893,7 +1898,7 @@ function parametric( vector, xRange, yRange, options={} ) {
default:
throw Error( 'Unsupported complex function case' );
}
else vertices.push( v );
} else vertices.push( v );

if ( 'colormap' in options ) {
if ( options.colormap === 'complexArgument' )
Expand Down
3 changes: 3 additions & 0 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ function colorFromHue( h ) {

function colorFromArg( x ) {

if ( !( typeof x === 'object' && 're' in x ) ) // from Math
x = { re: x, im: 0 };

var h = Math.atan2( x.im, x.re ) / Math.PI / 2;

return colorFromHue(h);
Expand Down
6 changes: 4 additions & 2 deletions src/plot/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ function parametric( vector, xRange, yRange, options={} ) {
var x = xRange[0] + j * xStep;
var v = vector(x,y);

if ( 'complexFunction' in options )
if ( 'complexFunction' in options ) {
if ( !( typeof v[2] === 'object' && 're' in v[2] ) ) // from Math
v[2] = { re: v[2], im: 0 };
switch( options.complexFunction ) {
case 're':
vertices.push( [ v[0], v[1], v[2].re ] );
Expand All @@ -104,7 +106,7 @@ function parametric( vector, xRange, yRange, options={} ) {
default:
throw Error( 'Unsupported complex function case' );
}
else vertices.push( v );
} else vertices.push( v );

if ( 'colormap' in options ) {
if ( options.colormap === 'complexArgument' )
Expand Down

0 comments on commit 5bd5ed1

Please sign in to comment.