Skip to content

Commit

Permalink
Note reusing recip
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcur committed Oct 31, 2024
1 parent 12bb7e4 commit db58fed
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ impl Triangle {
let bc = self.b.distance(self.c);
let ac = self.a.distance(self.c);

// [`Vec2::div`] also multiplies by the reciprocal of the argument, but as this reciprocal
// is reused below to calculate the radius, there's explicitly only one division needed.
let perimeter_recip = 1. / (ab + bc + ac);
let incenter = (self.a.to_vec2() * bc + self.b.to_vec2() * ac + self.c.to_vec2() * ab)
* perimeter_recip;
Expand Down

0 comments on commit db58fed

Please sign in to comment.