/**
 * gets the position where a ray intersects with a sphere
 *
 * @remarks
 *
 *
 */

import {Vector3} from 'three';
import {BaseRaySphereJsNode} from './_BaseRaySphere';
import {JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF} from '../utils/io/connections/Js';
import {JsLinesCollectionController} from './code/utils/JsLinesCollectionController';
import {Poly} from '../../Poly';
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;

const OUTPUT_NAME = 'position';
export class RayIntersectSphereJsNode extends BaseRaySphereJsNode {
	static override type() {
		return 'rayIntersectSphere';
	}
	override initializeNode() {
		super.initializeNode();
		this.io.outputs.setNamedOutputConnectionPoints([
			new JsConnectionPoint(OUTPUT_NAME, JsConnectionPointType.BOOLEAN, CONNECTION_OPTIONS),
		]);
	}
	override setLines(shadersCollectionController: JsLinesCollectionController) {
		const ray = this.variableForInput(shadersCollectionController, JsConnectionPointType.RAY);
		const sphere = this.variableForInput(shadersCollectionController, JsConnectionPointType.SPHERE);
		const out = this.jsVarName(OUTPUT_NAME);
		const tmpVarName = shadersCollectionController.addVariable(this, new Vector3());

		const func = Poly.namedFunctionsRegister.getFunction('rayIntersectSphere', this, shadersCollectionController);
		const bodyLine = func.asString(ray, sphere, tmpVarName);
		shadersCollectionController.addBodyOrComputed(this, [
			{dataType: JsConnectionPointType.VECTOR3, varName: out, value: bodyLine},
		]);
	}
}
