| 37 (x0 < x && x < x1) || (x1 < x && x < x0) |
37 (x0 < x && x < x1) || (x1 < x && x < x0) |
| 38 }) |
38 }) |
| 39 } |
39 } |
| 40 } |
40 } |
| 41 |
41 |
| |
42 #[replace_float_literals(F::cast_from(literal))] |
| 42 impl<'a, F: Float> Set<Loc<2, F>> for PlanarSimplex<F> { |
43 impl<'a, F: Float> Set<Loc<2, F>> for PlanarSimplex<F> { |
| 43 #[inline] |
44 #[inline] |
| 44 fn contains<I: Instance<Loc<2, F>>>(&self, z: I) -> bool { |
45 fn contains<I: Instance<Loc<2, F>>>(&self, z: I) -> bool { |
| 45 let &[x0, x1, x2] = &self.0; |
46 z.eval_ref(|&Loc([x, y])| { |
| 46 NPolygon([ |
47 let [Loc([x1, y1]), Loc([x2, y2]), Loc([x3, y3])] = self.0; |
| 47 [x0, x1].spanned_halfspace(), |
48 |
| 48 [x1, x2].spanned_halfspace(), |
49 let areax2 = (x1 - x3) * (y2 - y3) + (x2 - x3) * (y1 - y3); |
| 49 [x2, x0].spanned_halfspace(), |
50 |
| 50 ]) |
51 // Unscaled barycentric coordinates |
| 51 .contains(z) |
52 let s_unscaled = (y2 - y3) * (x - x3) + (x3 - x2) * (y - y3); |
| |
53 let t_unscaled = (y3 - y1) * (x - x3) + (x1 - x3) * (y - y3); |
| |
54 |
| |
55 (0.0 <= s_unscaled/*&& s <= areax2*/) |
| |
56 && (0.0 <= t_unscaled/*&& t <= areax2*/) |
| |
57 && s_unscaled + t_unscaled <= areax2 |
| |
58 }) |
| 52 } |
59 } |
| 53 } |
60 } |
| 54 |
61 |
| 55 trait P2Powers { |
62 trait P2Powers { |
| 56 type Output; |
63 type Output; |