Notifications
Clear all

[Closed] Did i make any low level mistake? Odd?

My scripts:


function insetCorner previousP currentP nextP insetDist = (
	local insetP = [0,0,0];
	currentP1 = currentP - [0,0,0];
	currentP2 = currentP - [0,0,0];
	dist1 = distance previousP currentP;
	dist2 = distance currentP nextP;
	--eixt if either segment is zero-length
	if dist1 == 0 or dist2 == 0 then return;
	--inset each of the two line segment
	insetP.x = ((currentP.y - previousP.y) / dist1 * insetDist);
	format "insetP.x should be:%
" ((currentP.y - previousP.y) / dist1 * insetDist);
	format "but insetP.x:%
" insetP.x
	previousP.x += insetP.x;
	currentP1.x += insetP.x;
	--print insetP;
	insetP.y = (previousP.x - currentP.x) / dist1 * insetDist;
	previousP.y += insetP.y;
	currentP1.y += insetP.y;
)
insetCorner [107.54,-12.5125,0] [127.58,52.5398,0] [190.69,27.4142,0] 10

My listener output:

insetCorner()
insetP.x should be:9.5568
but insetP.x:0.0
49.5957
OK

And to be simplify it should be

function insetCornerGood previousP currentP nextP insetDist = (
	insetP = [0,0,0];
	dist1 = distance previousP currentP;
	insetP.x  = ((currentP.y - previousP.y) / dist1 * insetDist);
	format "ideal way of insetP:%
" insetP;
)
insetCornerGood [107.54,-12.5125,0] [127.58,52.5398,0] [190.69,27.4142,0] 10

and the output is meaningful


insetCornerGood()
ideal way of insetP:[9.5568,0,0]
OK

1 Reply

So I think i lost the return value

if dist1 == 0 or dist2 == 0 then return 0;