Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to draw arc which is same as origin canvas arc api? #1840

Open
lzuntalented opened this issue Oct 15, 2018 · 0 comments
Open

how to draw arc which is same as origin canvas arc api? #1840

lzuntalented opened this issue Oct 15, 2018 · 0 comments

Comments

@lzuntalented
Copy link

Why DrawNode.drawCircle have not a param like startAngle?
It is often necessary to draw an arc.
When I write it by myself, DrawNode.drawSegment be called many time.

The error show me:

Failed to allocate buffer for DrawNode: buffer for 2034 vertices requested

So, could you help me to fix it?
It is very important to me. Thanks!

The code like:

drawCircle: function (handler, center, radius, startAngle, endAngle, segments, drawLineToCenter, lineWidth, color) {
		const _vertices = []; 
		const angle = startAngle;
        lineWidth = lineWidth || this._lineWidth;
        color = color || this._drawColor;
        var coef = endAngle / segments, i, len;
        for (i = 0; i <= segments; i++) {
            var rads = i * coef;
            var j = radius * Math.cos(rads + angle) + center.x;
            var k = radius * Math.sin(rads + angle) + center.y;
            _vertices.push([j, k]);
        }
        if (drawLineToCenter)
            _vertices.push([center.x, center.y]);

        for (i = 0, len = _vertices.length - 1; i < len; i += 1) {
        	const _from = {};
        	const _to = {};
            _from.x = _vertices[i][0];
            _from.y = _vertices[i][1];
            if (i === len - 1) {
            	if (endAngle > 2 * Math.PI) {
            		_to.x = _vertices[0][0];
            		_to.y = _vertices[0][1];
            	} else {
            		break;
            	}
            } else {
            	_to.x = _vertices[i + 1][0];
            	_to.y = _vertices[i + 1][1];
            }
            
            handler.drawSegment(_from, _to, lineWidth, color);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant