I am using Konva with Konva-React to draw a simple custom shape consisting of two perpendicular lines joined by an arc.
The API documentation for custom shape states that we can use the renderer to access the HTML5 Canvas context. As such I have created a drawing function that uses the Konva.Canvas renderer to display my shape, however the shape does not render as expected. See: https://codesandbox.io/s/react-konva-custom-shape-demo-hs3y4.
This renders correctly when using HTML5 Canvas https://codepen.io/anon/pen/voYNLR.
After several permutations (using typescript) I managed to generate an error message that highlights an issue with the arcTo command:
Expected 6 arguments, but got 5. TS2554
However https://www.w3.org/TR/2dcontext/ specifically states that arcTo has 5 parameters:
context.arcTo(x1, y1, x2, y2, radius)
On further investigation Context.d.ts states:
arc(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
arcTo(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void; <== Note 6 args (the same as arc)
The definition of arcTo in nodemodules\konva\lib\Context.js has what I believe to be a bug:
function Context(canvas) {
this.canvas = canvas;
this._context = canvas._canvas.getContext('2d');
……
Context.prototype.arc = function (a0, a1, a2, a3, a4, a5) {
this._context.arc(a0, a1, a2, a3, a4, a5);
};
Context.prototype.arcTo = function (a0, a1, a2, a3, a4, a5) {
this._context.arc(a0, a1, a2, a3, a4, a5);
};
Notice here that the implementation of the prototype for arcTo uses _context.arc in place of arcTo. I would appreciate any validation of these findings, or some background if this is intended behaviour.
I have created a fork with a modified arcTo signature here: https://github.com/piriej/konva (warning: work in progress)
Kind Regards
Jeff
That looks like a bug in wrapping of context methods inside Konva codebase.
As workaround you can call arcTo directly:
context._context.arcTo(150, 20, 150, 70, 50);
Demo: https://codesandbox.io/s/react-konva-custom-shape-demo-4u6kz
Related
everyone. I'm trying to do an iterative equation solver, where I put an equation then each iteration substitutes the X for a value then solves it. I'm having a hard time since the iterated function is considered a string. Any help is appreciated, thank you. The equation needs to be dynamic and be solved via iterations.
I tried calling the =substitute cell and end up having invalid data, since it reads as string.
try:
=BYROW(A9:A24, LAMBDA(ii, INDEX(QUERY(,
"select "®EXREPLACE(REGEXREPLACE(REGEXREPLACE(B2, "\^\d+", REPT("*x",
REGEXEXTRACT(B2, "\^(\d+)")-1)), "\(", "*("), "x", ii&"")), 2)))
logic:
caret ^ is not supported by QUERY so we first transform ^2 into an alternative. we know x^2 is equal to x*x so we extract that 2 and subtract 1 and REPT *x one time
next, we need to add multiplication as ()() needs to become ()*() same as 50x to 50*x
then we substitute x with value and evaluate the string with QUERY's SQL ## logic:
basically, we transform your:
-50(x)-1/2(-9.81)(x^2)+35
into:
-50*(0)-1/2*(-9.81)*(0*0)+35
-50*(1)-1/2*(-9.81)*(1*1)+35
-50*(2)-1/2*(-9.81)*(2*2)+35
etc.
UPDATE:
x^n where n is <1 are unachievable with REPT method and QUERY does not support roots so we can use a script to convert a text string into the formula
poor script example:
function onEdit(){
var sheet = SpreadsheetApp.getActiveSheet();
var source1= sheet.getRange('F7');
var source2= sheet.getRange('F8');
var formula1 = source1.getValue();
var formula2 = source2.getValue();
var target1 = sheet.getRange('B7');
var target2 = sheet.getRange('B8');
target1.setFormula(formula1);
target2.setFormula(formula2);
}
where F7 contains:
=BYROW(A7:A23, LAMBDA(i, "POW("&INDEX(QUERY(, "select "®EXREPLACE(
SUBSTITUTE(REGEXEXTRACT(B3, "(.+)\^"), ")(", ")*("), "x", i&"")), 2)&","&
REGEXEXTRACT(B3, "\^\((.+)\)")&")"))
I have in my preamble:
\pgfplotsset{
compat=newest,
/pgf/declare function={
g(\x) = -x^4+2*x^3-x-2;
},
}
and then later in the body I have a plot of the function g(x).
I would like to be able to reference g(x) outside of a pgfplots environment, and have it show up as the defined expression.
Something like $g(x)=\pgfdisplay{g(\x)}$
and have it render the same way $g(x)=-x^4+2*x^3-x-2$ would render.
I don't understand why this is so hard to find, but basically, I have some values that I calculated in a macro in ImageJ, and when I print using this method:
print("Radius 1: "+r1);
The string and value both get printed in the same cell. I would like to make this more friendly for Matlab when I have to plot so was wondering if there was a way to print it in separate columns?
EDIT:
SOLVED I realized that you don't use print, it's like this:
setResult("Radius", 0, r1);
setResult("Radius", 1, r2);
setResult("Radius", 2, r3);
setResult("Arc Length",0, al1);
setResult("Arc Length",1, al2);
setResult("Arc Length",2, al3);
When I write the expression for the partial derivative of a function, diff(f(x_1,x_2),x_1,1), for a function f created with funmake(f,[x_1,x_2]), the returned output is
However, when copying and pasting the output of the partial derivative, what I get instead is 'diff(f(x_1,x_2)), which stands for the total derivative of the function f instead of the partial derivative:
Since total and partial derivatives are not the same thing, this is inappropriate. What is the reason for this behavior? How could it be fixed?
As Robert Dodier wrote in the comments, this is a bug in wxMaxima. It is caused by the code that handles subscripts. (In your case, _1 and _2). Subscript cells don't implement a function that is supposed to serialize the variable of differentiation.
To work around the issue, you can avoid using subscripts. Changing x_1 and x_2 to x1 and x2 works:
(%i1) diff(f(x1,x2),x1,1); /* OK */
(%i2) diff(f(x_1,x_2),x_1,1); /* NOT OK */
So when I try and map this rgb value onto my data:
image=love.image.newImageData(WIDTH,HEIGHT,"rgba16f")
image:mapPixel(pixelFunction)
image2=love.graphics.newImage(image)
function pixelFunction(x, y, r, g, b, a)
return 0,50,0,255
end
I get this
As you can see this is something like (0,255,0,255) not the rgb value I wanted, in fact it seems only able to render the max red green or blue value, making the function ponitless
As one could guess from the fact that only extreme colors are generated, the value 50 is beyond the dynamic range. Using rgba representation in fractions of one (0, 50/255, 0, 1) does result in dark green.
(0,50,0,255) used to work in love 10. According to wiki it should work in love 11 with "rgba16f" that you seem to set. But it doesn't. Proceed to their bug reports section.
Also, please note that minimal reproducible example for the question should have been done along these lines:
WIDTH=300; HEIGHT=300;
imageData=love.image.newImageData(WIDTH,HEIGHT,'rgba16f')
function pixelFunction(x, y, r, g, b, a)
return 0,50/255,0,255
end
imageData:mapPixel(pixelFunction)
image=love.graphics.newImage(imageData)
function love.draw()
love.graphics.draw(image,0,0)
end
And yes, you've botched the order of definition and usage.