Skip to content

Commit

Permalink
Use inbuilt function instead of helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitish-bot authored and Keavon committed Dec 28, 2024
1 parent 5fcade3 commit fbaad91
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions editor/src/messages/tool/tool_messages/text_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,29 +309,6 @@ impl TextToolData {
font_cache: &FontCache,
responses: &mut VecDeque<Message>,
) -> TextToolFsmState {
fn is_point_in_triangle(p: DVec2, a: DVec2, b: DVec2, c: DVec2) -> bool {
let v0 = c - a;
let v1 = b - a;
let v2 = p - a;

let dot00 = v0.dot(v0);
let dot01 = v0.dot(v1);
let dot02 = v0.dot(v2);
let dot11 = v1.dot(v1);
let dot12 = v1.dot(v2);

let denom = dot00 * dot11 - dot01 * dot01;
if denom == 0.0 {
return false; // Degenerate triangle
}
let inv_denom = 1.0 / denom;

let u = (dot11 * dot02 - dot01 * dot12) * inv_denom;
let v = (dot00 * dot12 - dot01 * dot02) * inv_denom;

u >= 0.0 && v >= 0.0 && (u + v) <= 1.0
}

// Check if the user has selected an existing text layerQ
if let Some(clicked_text_layer_path) = document
.metadata()
Expand All @@ -345,9 +322,7 @@ impl TextToolData {
let transformed_quad = document.metadata().transform_to_viewport(layer) * quad;
let mouse = DVec2::new(input.mouse.position.x, input.mouse.position.y);

if is_point_in_triangle(mouse, transformed_quad.0[0], transformed_quad.0[1], transformed_quad.0[2])
|| is_point_in_triangle(mouse, transformed_quad.0[0], transformed_quad.0[2], transformed_quad.0[3])
{
if transformed_quad.contains(mouse) {
return true;
}
false
Expand Down

0 comments on commit fbaad91

Please sign in to comment.