diff --git a/src/infrastructure/rendering/gpu_structures.rs b/src/infrastructure/rendering/gpu_structures.rs index 5cbaec5..4699f0c 100644 --- a/src/infrastructure/rendering/gpu_structures.rs +++ b/src/infrastructure/rendering/gpu_structures.rs @@ -510,14 +510,14 @@ impl CandleGeometry { // Create a rectangle as two triangles without gaps let segment_vertices = [ - // First triangle + // First triangle (CCW) CandleVertex::indicator_vertex(x1 - perp_x, y1 - perp_y, indicator_type), - CandleVertex::indicator_vertex(x1 + perp_x, y1 + perp_y, indicator_type), CandleVertex::indicator_vertex(x2 - perp_x, y2 - perp_y, indicator_type), - // Second triangle CandleVertex::indicator_vertex(x1 + perp_x, y1 + perp_y, indicator_type), - CandleVertex::indicator_vertex(x2 + perp_x, y2 + perp_y, indicator_type), + // Second triangle (CCW) + CandleVertex::indicator_vertex(x1 + perp_x, y1 + perp_y, indicator_type), CandleVertex::indicator_vertex(x2 - perp_x, y2 - perp_y, indicator_type), + CandleVertex::indicator_vertex(x2 + perp_x, y2 + perp_y, indicator_type), ]; vertices.extend_from_slice(&segment_vertices); diff --git a/tests/indicator_vertices.rs b/tests/indicator_vertices.rs index a74ad74..664db72 100644 --- a/tests/indicator_vertices.rs +++ b/tests/indicator_vertices.rs @@ -23,6 +23,22 @@ fn indicator_line_vertex_count() { assert!((verts[0].color_type - 2.0).abs() < f32::EPSILON); } +#[wasm_bindgen_test] +fn indicator_line_segments_are_ccw() { + let points = [(-0.5, 0.0), (0.5, 0.0)]; + let verts = CandleGeometry::create_indicator_line_vertices(&points, IndicatorType::SMA20, 0.1); + + let orient_first = (verts[1].position_x - verts[0].position_x) + * (verts[2].position_y - verts[0].position_y) + - (verts[1].position_y - verts[0].position_y) * (verts[2].position_x - verts[0].position_x); + let orient_second = (verts[4].position_x - verts[3].position_x) + * (verts[5].position_y - verts[3].position_y) + - (verts[4].position_y - verts[3].position_y) * (verts[5].position_x - verts[3].position_x); + + assert!(orient_first > 0.0); + assert!(orient_second > 0.0); +} + #[wasm_bindgen_test] fn indicator_line_color_types() { let pts = [(-1.0, 0.0), (1.0, 1.0)];