Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/infrastructure/rendering/gpu_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions tests/indicator_vertices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
Loading