<commit_before>package phoenix.geometry;

import phoenix.geometry.Vertex ;
import phoenix.Vector;
import phoenix.geometry.Geometry;
import phoenix.geometry.TextureCoord;
import phoenix.Batcher;
import phoenix.Circle;

class CircleGeometry extends Geometry {

	public function new( options : Dynamic ) {

		super(options);
        
        if(options == null) return;

        if(options.end_angle == null) {
        	options.end_angle = 360;
        }        

        if(options.start_angle == null) {
        	options.start_angle = 0;
        }

        if(options.steps == null) {
        	options.steps = Luxe.utils.geometry.segments_for_smooth_circle( options.r );
        }

            //Apply the new options rect
		set( new Circle(options.x, options.y, options.r), options.steps, luxe.utils.Maths.degToRad(options.start_angle), luxe.utils.Maths.degToRad(options.end_angle) );

        if(options.enabled != null) enabled = options.enabled;

	} //new

	public function set( _circle:Circle, _steps:Int, _start_angle:Float=0, _end_angle:Float=360 ) {

			//adapted from
			//http://slabode.exofire.net/circle_draw.shtml
		primitive_type = PrimitiveType.triangle_fan;

			//add the center of the circle
		var center : Vertex = new Vertex( new Vector( 0, 0 ) );
			center.color = color;

			var _range = _end_angle - _start_angle;

				//Precompute the value based on segments
			var theta = _range / _steps;

			var tangential_factor = Math.tan( theta );
			var radial_factor = Math.cos( theta );
			
			var x : Float = _circle.r * Math.cos(_start_angle); 
			var y : Float = _circle.r * Math.sin(_start_angle); 
		    
			for( i in 0 ... _steps ) {

				var __x = x;
				var __y = y;

				var vert = new Vertex(new Vector( __x,__y ));
					vert.color = color;

				add(vert);
		        
					var tx = -y;
					var ty = x;
			        
					x += tx * tangential_factor; 
					y += ty * tangential_factor; 
			        
					x *= radial_factor;
					y *= radial_factor;

			} //for

		//and finally, set the position
		pos.set( _circle.x, _circle.y );
	}

} //CircleGeometry<commit_msg>RingGeometry; Tightening up circle implementation for reuse as ellipse and making it more flexible<commit_after>package phoenix.geometry;

import phoenix.geometry.Vertex ;
import phoenix.Vector;
import phoenix.geometry.Geometry;
import phoenix.geometry.TextureCoord;
import phoenix.Batcher;
import phoenix.Circle;

class CircleGeometry extends Geometry {

	public function new( options : Dynamic ) {

		super(options);
        
        if(options == null) return;

            //some default values so that the circle is visible with no values
        var _radius = 16;

        if(options.end_angle == null) {
        	options.end_angle = 360;
        }        

        if(options.start_angle == null) {
        	options.start_angle = 0;
        }

        if(options.r != null) {
            _radius = options.r;
        }

        if(options.steps == null) {
            if(options.smooth == null) {
                options.steps = Luxe.utils.geometry.segments_for_smooth_circle( _radius );
            } else {
                var _smooth : Float = options.smooth;
                options.steps = Luxe.utils.geometry.segments_for_smooth_circle( _radius, _smooth );
            }
        }

            //Apply the new options 
		set( options.x, options.y, _radius, options.steps, options.start_angle, options.end_angle );

        if(options.enabled != null) enabled = options.enabled;

	} //new

	public function set( _x:Float, _y:Float, _r:Float, _steps:Int, _start_angle:Float=0, _end_angle:Float=360 ) {

			//adapted from
			//http://slabode.exofire.net/circle_draw.shtml
		primitive_type = PrimitiveType.triangle_fan;

			//add the center of the circle
		var center : Vertex = new Vertex( new Vector( 0, 0 ) );
			center.color = color;

            var _start_angle_rad = luxe.utils.Maths.degToRad(_start_angle);
            var _end_angle_rad = luxe.utils.Maths.degToRad(_end_angle);

			var _range = _end_angle_rad - _start_angle_rad;

				//Precompute the value based on segments
			var theta = _range / _steps;

			var tangential_factor = Math.tan( theta );
			var radial_factor = Math.cos( theta );
			
			var x : Float = _r * Math.cos(_start_angle_rad); 
			var y : Float = _r * Math.sin(_start_angle_rad);
		    
			for( i in 0 ... _steps ) {

				var __x = x;
				var __y = y;

				var vert = new Vertex(new Vector( __x,__y ));
					vert.color = color;

				add(vert);
		        
					var tx = -y;
					var ty = x;
			        
					x += tx * tangential_factor; 
					y += ty * tangential_factor; 
			        
					x *= radial_factor;
					y *= radial_factor;                    

			} //for

		//and finally, set the position
		pos.set( _x, _y );
	}

} //CircleGeometry
{'fraction_non_alphanumeric': 0.10824958123953099, 'fraction_numerical': 0.005025125628140704, 'mean_word_length': 2.2990331491712706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '228368', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1514, 'n_words': 378}