pub struct TernaryGeometry { /* private fields */ }Expand description
An equilateral ternary triangle and its component-to-vertex assignment.
Implementations§
Source§impl TernaryGeometry
impl TernaryGeometry
Sourcepub const fn new(
orientation: TriangleOrientation,
vertex_order: VertexOrder,
) -> Self
pub const fn new( orientation: TriangleOrientation, vertex_order: VertexOrder, ) -> Self
Construct geometry with the given orientation and component order.
Sourcepub const fn orientation(self) -> TriangleOrientation
pub const fn orientation(self) -> TriangleOrientation
Return the triangle orientation.
Sourcepub const fn vertex_order(self) -> VertexOrder
pub const fn vertex_order(self) -> VertexOrder
Return the component-to-vertex assignment.
Sourcepub fn vertex(self, component: Component) -> TernaryCartesian
pub fn vertex(self, component: Component) -> TernaryCartesian
Return the logical Cartesian vertex for a semantic component.
Sourcepub fn vertices(self) -> [TernaryCartesian; 3]
pub fn vertices(self) -> [TernaryCartesian; 3]
Return the vertices in stable semantic A/B/C order.
Sourcepub fn triangle_edge(self, edge: TriangleEdge) -> CartesianSegment
pub fn triangle_edge(self, edge: TriangleEdge) -> CartesianSegment
Return a complete directed geometric triangle edge.
Sourcepub fn triangle_edges(self) -> [(TriangleEdge, CartesianSegment); 3]
pub fn triangle_edges(self) -> [(TriangleEdge, CartesianSegment); 3]
Return all complete edges in directed boundary order.
Sourcepub fn visible_edges(
self,
viewport: TernaryViewport,
tolerance: Tolerance,
) -> Result<Vec<VisibleTriangleEdge>, Error>
pub fn visible_edges( self, viewport: TernaryViewport, tolerance: Tolerance, ) -> Result<Vec<VisibleTriangleEdge>, Error>
Clip every original triangle edge and retain its identity and parameters.
Sourcepub fn component_isoline(
self,
component: Component,
value: f64,
tolerance: Tolerance,
) -> Result<CartesianSegment, Error>
pub fn component_isoline( self, component: Component, value: f64, tolerance: Tolerance, ) -> Result<CartesianSegment, Error>
Construct the full-triangle segment where a semantic component equals value.
Values within tolerance of zero or one are snapped to that boundary.
value = 0 returns the opposite edge and value = 1 returns a
zero-length segment at the component vertex.
Sourcepub fn visible_component_isoline(
self,
component: Component,
value: f64,
viewport: TernaryViewport,
tolerance: Tolerance,
) -> Result<Option<CartesianSegment>, Error>
pub fn visible_component_isoline( self, component: Component, value: f64, viewport: TernaryViewport, tolerance: Tolerance, ) -> Result<Option<CartesianSegment>, Error>
Construct and clip one semantic component isoline to a viewport.
Sourcepub fn project(
self,
point: TernaryPoint,
normalization: Normalization,
tolerance: Tolerance,
) -> Result<TernaryCartesian, Error>
pub fn project( self, point: TernaryPoint, normalization: Normalization, tolerance: Tolerance, ) -> Result<TernaryCartesian, Error>
Validate and project a composition into the normalised ternary plane.
The explicit policy permits source data using a non-unit required sum. After validation, the three weights are divided by their validated sum before the barycentric weighted sum is calculated.
use plotters_ternary::{Normalization, TernaryGeometry, TernaryPoint, Tolerance};
let point = TernaryPoint::new(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0);
let projected = TernaryGeometry::default().project(
point,
Normalization::RequireUnitSum,
Tolerance::default(),
)?;
assert!((projected.x - 0.5).abs() < 1.0e-12);Sourcepub fn unproject(
self,
cartesian: TernaryCartesian,
tolerance: Tolerance,
) -> Result<TernaryPoint, Error>
pub fn unproject( self, cartesian: TernaryCartesian, tolerance: Tolerance, ) -> Result<TernaryPoint, Error>
Recover unit-sum A/B/C component weights from a Cartesian point.
Points materially outside the full triangle return
Error::CartesianOutsideTriangle. Weights whose absolute value is at
most the absolute tolerance are set to zero, then the remaining weights
are rescaled to sum to one. This admits small boundary round-off without
silently clamping external points.
use plotters_ternary::{TernaryCartesian, TernaryGeometry, Tolerance};
let point = TernaryGeometry::default()
.unproject(TernaryCartesian::new(0.5, 0.0), Tolerance::default())?;
assert_eq!(point.as_array(), [0.0, 0.5, 0.5]);Sourcepub fn classify(
self,
cartesian: TernaryCartesian,
tolerance: Tolerance,
) -> Result<TrianglePointLocation, Error>
pub fn classify( self, cartesian: TernaryCartesian, tolerance: Tolerance, ) -> Result<TrianglePointLocation, Error>
Classify a finite Cartesian point against the complete ternary triangle.
Non-finite coordinates are rejected because they have no geometric location. This operation does not consider future rectangular viewports.