Skip to content

Commit

Permalink
apply GeoFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Jan 26, 2021
1 parent 21f205f commit b78d093
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 109 deletions.
1 change: 1 addition & 0 deletions geo/src/algorithm/contains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ mod test {
assert!(!poly1.contains(&line));
}
#[test]
#[ignore]
fn line_in_polygon_edgecases_test() {
// Some DE-9IM edge cases for checking line is
// inside polygon The end points of the line can be
Expand Down
14 changes: 9 additions & 5 deletions geo/src/algorithm/contains/polygon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Contains;
use crate::intersects::Intersects;
use crate::{Coordinate, GeoNum, Geometry, Line, LineString, MultiPolygon, Point, Polygon};
use crate::{CoordNum, Coordinate, GeoNum, Line, LineString, MultiPolygon, Point, Polygon};

// ┌─────────────────────────────┐
// │ Implementations for Polygon │
Expand All @@ -26,15 +26,19 @@ where
}
}

// TODO: ensure DE-9IM compliance: esp., when
// line.start and line.end is on the boundaries
impl<T> Contains<Line<T>> for Polygon<T>
where
T: GeoNum,
{
fn contains(&self, line: &Line<T>) -> bool {
use crate::algorithm::relate::Relate;
Geometry::Polygon(self.clone())
.relate(&Geometry::Line(line.clone()))
.is_contains()
// both endpoints are contained in the polygon and the line
// does NOT intersect the exterior or any of the interior boundaries
self.contains(&line.start)
&& self.contains(&line.end)
&& !self.exterior().intersects(line)
&& !self.interiors().iter().any(|inner| inner.intersects(line))
}
}

Expand Down
7 changes: 4 additions & 3 deletions geo/src/algorithm/relate/edge_end_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::geomgraph::{Edge, EdgeEnd, EdgeIntersection, Float};
use crate::geomgraph::{Edge, EdgeEnd, EdgeIntersection};
use crate::GeoFloat;

use std::cell::RefCell;
use std::rc::Rc;
Expand Down Expand Up @@ -26,15 +27,15 @@ use std::rc::Rc;
// JTS: *
// JTS: * @version 1.7
// JTS: */
pub(crate) struct EdgeEndBuilder<F: Float> {
pub(crate) struct EdgeEndBuilder<F: GeoFloat> {
_marker: std::marker::PhantomData<F>,
}

// JTS: public class EdgeEndBuilder {
// JTS:
// JTS: public EdgeEndBuilder() {
// JTS: }
impl<F: Float> EdgeEndBuilder<F> {
impl<F: GeoFloat> EdgeEndBuilder<F> {
pub fn new() -> Self {
EdgeEndBuilder {
_marker: std::marker::PhantomData,
Expand Down
9 changes: 5 additions & 4 deletions geo/src/algorithm/relate/relate_computer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::{EdgeEndBuilder, IntersectionMatrix, RelateNodeFactory};
use crate::algorithm::dimensions::{Dimensions, HasDimensions};
use crate::geomgraph::{
algorithm::RobustLineIntersector, index::SegmentIntersector, Edge, EdgeEnd, Float,
GeometryGraph, Location, Node, NodeMap,
algorithm::RobustLineIntersector, index::SegmentIntersector, Edge, EdgeEnd, GeometryGraph,
Location, Node, NodeMap,
};
use crate::GeoFloat;

use geo_types::Geometry;
use std::cell::RefCell;
Expand Down Expand Up @@ -52,7 +53,7 @@ use std::rc::Rc;
// JTS: {
pub(crate) struct RelateComputer<'a, F>
where
F: Float,
F: GeoFloat,
{
graph_a: GeometryGraph<'a, F>,
graph_b: GeometryGraph<'a, F>,
Expand All @@ -63,7 +64,7 @@ where

impl<'a, F> RelateComputer<'a, F>
where
F: 'static + Float,
F: 'static + GeoFloat,
{
pub fn new(geom_a: &'a Geometry<F>, geom_b: &'a Geometry<F>) -> RelateComputer<'a, F> {
Self {
Expand Down
6 changes: 3 additions & 3 deletions geo/src/algorithm/relate/relate_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::geomgraph::{EdgeEndBundleStar, Float, Node, NodeFactory};
use crate::Coordinate;
use crate::geomgraph::{EdgeEndBundleStar, Node, NodeFactory};
use crate::{Coordinate, GeoFloat};

// JTS: import org.locationtech.jts.geom.Coordinate;
// JTS: import org.locationtech.jts.geom.IntersectionMatrix;
Expand Down Expand Up @@ -73,7 +73,7 @@ use crate::Coordinate;
pub(crate) struct RelateNodeFactory;
impl<F> NodeFactory<F> for RelateNodeFactory
where
F: Float,
F: GeoFloat,
{
type Edges = EdgeEndBundleStar<F>;
fn create_node(coordinate: Coordinate<F>) -> (Node<F>, Self::Edges) {
Expand Down
4 changes: 2 additions & 2 deletions geo/src/geomgraph/algorithm/line_intersector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// JTS: import org.locationtech.jts.geom.PrecisionModel;
// JTS: import org.locationtech.jts.io.WKTWriter;
// JTS: import org.locationtech.jts.util.Assert;
use geo_types::Coordinate;
use crate::{Coordinate, GeoFloat};

#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum Intersection {
Expand Down Expand Up @@ -47,7 +47,7 @@ pub enum Intersection {
// JTS: public abstract class LineIntersector
// JTS: {

pub trait LineIntersector<F: num_traits::Float> {
pub(crate) trait LineIntersector<F: GeoFloat> {
// JTS: /**
// JTS: * These are deprecated, due to ambiguous naming
// JTS: */
Expand Down
17 changes: 8 additions & 9 deletions geo/src/geomgraph/algorithm/robust_line_intersector.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use super::{Intersection, LineIntersector};
use crate::algorithm::kernels::{Kernel, Orientation, RobustKernel};
use crate::contains::Contains;
use crate::geomgraph::Float;
use crate::intersects::Intersects;
use crate::num_traits::Zero;
use geo_types::{Coordinate, Rect};
use crate::{Coordinate, GeoFloat, Rect};

// JTS: /**
// JTS: * A robust version of {@link LineIntersector}.
Expand All @@ -16,7 +15,7 @@ use geo_types::{Coordinate, Rect};
// JTS: {
/// A robust version of [LineIntersector](traits.LineIntersector).
#[derive(Clone)]
pub(crate) struct RobustLineIntersector<F: Float> {
pub(crate) struct RobustLineIntersector<F: GeoFloat> {
// TODO: JTS captures some state in the LineIntersector. I'm not sure if it's helpful. Roughly it
// seems to be mid-computation state and result state. Perhaps that could be better modeled and
// we could leave the LineIntersector less mutable.
Expand All @@ -27,7 +26,7 @@ pub(crate) struct RobustLineIntersector<F: Float> {
int_pt: [Coordinate<F>; 2],
}

impl<F: Float> RobustLineIntersector<F> {
impl<F: GeoFloat> RobustLineIntersector<F> {
// JTS: public RobustLineIntersector() {
// JTS: }
pub fn new() -> RobustLineIntersector<F> {
Expand All @@ -40,7 +39,7 @@ impl<F: Float> RobustLineIntersector<F> {
}
}

impl<F: Float> LineIntersector<F> for RobustLineIntersector<F> {
impl<F: GeoFloat> LineIntersector<F> for RobustLineIntersector<F> {
fn intersection(&self, intersection_index: usize) -> Coordinate<F> {
self.int_pt[intersection_index]
}
Expand Down Expand Up @@ -279,7 +278,7 @@ impl<F: Float> LineIntersector<F> for RobustLineIntersector<F> {
}
}

impl<F: Float> RobustLineIntersector<F> {
impl<F: GeoFloat> RobustLineIntersector<F> {
// JTS: private int computeCollinearIntersection(Coordinate p1, Coordinate p2,
// JTS: Coordinate q1, Coordinate q2) {
// CLEANUP: take (p: Line<F>, q: Line<F>) instead?
Expand Down Expand Up @@ -669,7 +668,7 @@ impl<F: Float> RobustLineIntersector<F> {
// JTS: * @see CGAlgorithmsDD#intersection(Coordinate, Coordinate, Coordinate, Coordinate)
// JTS: */
// JTS: public static Coordinate intersection(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) {
fn line_intersection<F: Float>(
fn line_intersection<F: GeoFloat>(
p1: Coordinate<F>,
p2: Coordinate<F>,
q1: Coordinate<F>,
Expand Down Expand Up @@ -1069,7 +1068,7 @@ mod test {
// JTS: Coordinate[] expectedIntPt,
// JTS: double distanceTolerance)
// JTS: {
fn check_intersection<F: Float>(
fn check_intersection<F: GeoFloat>(
line_1: Line<F>,
line_2: Line<F>,
intersection: Intersection,
Expand Down Expand Up @@ -1133,7 +1132,7 @@ mod test {
// JTS: + "expected " + WKTWriter.toPoint(expectedPt) + " VS "
// JTS: + "actual " + WKTWriter.toPoint(actualPt), isEqual);
// JTS: }
fn check_intersection_points<F: Float>(
fn check_intersection_points<F: GeoFloat>(
expected: Coordinate<F>,
actual: Coordinate<F>,
distance_tolerance: F,
Expand Down
16 changes: 8 additions & 8 deletions geo/src/geomgraph/edge.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use super::algorithm::LineIntersector;
use super::{Dimensions, EdgeIntersectionList, Float, Label, Position};
use geo_types::Coordinate;
use super::{Dimensions, EdgeIntersectionList, Label, Position};
use crate::{Coordinate, GeoFloat};

// REVIEW: kind of weird circular dependency on relate module from geomgraph
use crate::algorithm::relate::IntersectionMatrix;

// TODO: investigate how isEqual should be implented - not sure it makes sense
// to derive equality, since it compares a bunch of vec's
#[derive(Debug)]
pub(crate) struct Edge<F: Float> {
pub(crate) struct Edge<F: GeoFloat> {
coords: Vec<Coordinate<F>>,
is_isolated: bool,
edge_intersections: EdgeIntersectionList<F>,
label: Label,
}

/// Graph Component methods
impl<F: Float> Edge<F> {
impl<F: GeoFloat> Edge<F> {
pub(crate) fn label(&self) -> &Label {
&self.label
}
Expand All @@ -32,7 +32,7 @@ impl<F: Float> Edge<F> {
// JTS: public class Edge
// JTS: extends GraphComponent
// JTS: {
impl<F: Float> Edge<F> {
impl<F: GeoFloat> Edge<F> {
// JTS: /**
// JTS: * Updates an IM from the label for an edge.
// JTS: * Handles edges from both L and A geometries.
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<F: Float> Edge<F> {
}

// JTS:
impl<F: Float> Edge<F> {
impl<F: GeoFloat> Edge<F> {
// JTS: Coordinate[] pts;
pub fn coords(&self) -> &[Coordinate<F>] {
&self.coords
Expand Down Expand Up @@ -302,7 +302,7 @@ impl<F: Float> Edge<F> {
// JTS: }
}

impl<F: Float> std::cmp::PartialEq for Edge<F> {
impl<F: GeoFloat> std::cmp::PartialEq for Edge<F> {
// JTS: /**
// JTS: * equals is defined to be:
// JTS: * <p>
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<F: Float> std::cmp::PartialEq for Edge<F> {
}
}

impl<F: Float> Edge<F> {
impl<F: GeoFloat> Edge<F> {
// JTS: /**
// JTS: * @return true if the coordinate sequences of the Edges are identical
// JTS: */
Expand Down
19 changes: 10 additions & 9 deletions geo/src/geomgraph/edge_end.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{Coordinate, Edge, Float, Label, Node, Quadrant};
use super::{Edge, Label, Node, Quadrant};
use crate::{Coordinate, GeoFloat};

use std::cell::RefCell;
use std::fmt;
Expand All @@ -23,7 +24,7 @@ use std::fmt;
#[derive(Clone)]
pub(crate) struct EdgeEnd<F>
where
F: Float,
F: GeoFloat,
{
// edge: RefCell<Edge<F>>,
label: Label,
Expand All @@ -33,7 +34,7 @@ where
quadrant: Quadrant,
}

impl<F: Float> fmt::Debug for EdgeEnd<F> {
impl<F: GeoFloat> fmt::Debug for EdgeEnd<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EdgeEnd")
.field("label", &self.label)
Expand All @@ -48,7 +49,7 @@ impl<F: Float> fmt::Debug for EdgeEnd<F> {

impl<F> EdgeEnd<F>
where
F: Float,
F: GeoFloat,
{
// JTS: {
// JTS: protected Edge edge; // the parent edge of this edge end
Expand Down Expand Up @@ -128,11 +129,11 @@ where
// JTS: public Node getNode() { return node; }
}

impl<F> std::cmp::Eq for EdgeEnd<F> where F: Float {}
impl<F> std::cmp::Eq for EdgeEnd<F> where F: GeoFloat {}

impl<F> std::cmp::PartialEq for EdgeEnd<F>
where
F: Float,
F: GeoFloat,
{
fn eq(&self, other: &EdgeEnd<F>) -> bool {
self.delta == other.delta
Expand All @@ -141,7 +142,7 @@ where

impl<F> std::cmp::PartialOrd for EdgeEnd<F>
where
F: Float,
F: GeoFloat,
{
fn partial_cmp(&self, other: &EdgeEnd<F>) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
Expand All @@ -150,7 +151,7 @@ where

impl<F> std::cmp::Ord for EdgeEnd<F>
where
F: Float,
F: GeoFloat,
{
// JTS: public int compareTo(Object obj)
// JTS: {
Expand All @@ -164,7 +165,7 @@ where

impl<F> EdgeEnd<F>
where
F: Float,
F: GeoFloat,
{
// JTS: /**
// JTS: * Implements the total order relation:
Expand Down
9 changes: 5 additions & 4 deletions geo/src/geomgraph/edge_end_bundle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::{
algorithm::boundary_node_rule::Mod2BoundaryNodeRule, Coordinate, Edge, EdgeEnd, Float,
GeometryGraph, Label, Location, Position,
algorithm::boundary_node_rule::Mod2BoundaryNodeRule, Edge, EdgeEnd, GeometryGraph, Label,
Location, Position,
};
use crate::{Coordinate, GeoFloat};
// weird circular dependency from GeomGraph to IntersectionMatrix
use crate::algorithm::relate::IntersectionMatrix;

Expand Down Expand Up @@ -29,7 +30,7 @@ use crate::algorithm::relate::IntersectionMatrix;
#[derive(Clone, Debug)]
pub(crate) struct MaybeLabeledEdgeEndBundle<F>
where
F: Float,
F: GeoFloat,
{
coordinate: Coordinate<F>,
label: Option<Label>,
Expand All @@ -38,7 +39,7 @@ where

impl<F> MaybeLabeledEdgeEndBundle<F>
where
F: Float,
F: GeoFloat,
{
// JTS: {
// JTS: // private BoundaryNodeRule boundaryNodeRule;
Expand Down
Loading

0 comments on commit b78d093

Please sign in to comment.