Skip to content

Commit

Permalink
Merge pull request #98 from hannobraun/topology
Browse files Browse the repository at this point in the history
Refactor construction of line segments
  • Loading branch information
hannobraun authored Jan 27, 2022
2 parents 8732095 + 2d97f89 commit 7ddb500
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
15 changes: 11 additions & 4 deletions src/kernel/shapes/sketch.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use nalgebra::point;
use parry3d_f64::bounding_volume::AABB;

use crate::{
debug::DebugInfo,
kernel::{
geometry::Surface,
geometry::{Curve, Line, Surface},
topology::{
edges::{Edge, Edges},
faces::{Face, Faces},
Expand Down Expand Up @@ -45,10 +46,16 @@ impl Shape for fj::Sketch {
// Can't panic, we passed `2` to `windows`.
//
// Can be cleaned up, once `array_windows` is stable.
let a = window[0];
let b = window[1];
let start = window[0];
let end = window[1];

edges.push(Edge::line_segment(a, b));
let line = Curve::Line(Line {
origin: start,
dir: end - start,
});
let edge = Edge::new(line, point![0.], point![1.]);

edges.push(edge);
}

Edges::single_cycle(edges)
Expand Down
25 changes: 11 additions & 14 deletions src/kernel/topology/edges.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use nalgebra::{point, vector};
use nalgebra::vector;
use parry2d_f64::shape::Segment as Segment2;
use parry3d_f64::{math::Isometry, shape::Segment as Segment3};

use crate::{
kernel::geometry::{Circle, Curve, Line, Surface},
kernel::geometry::{Circle, Curve, Surface},
math::Point,
};

Expand Down Expand Up @@ -209,6 +209,15 @@ pub struct Edge {
}

impl Edge {
/// Construct an edge
pub fn new(curve: Curve, start: Point<1>, end: Point<1>) -> Self {
Self {
curve,
vertices: Some([start, end]),
reverse: false,
}
}

/// Create an arc
///
/// So far, the name of this method is a bit ambitious, as only full circles
Expand All @@ -224,18 +233,6 @@ impl Edge {
}
}

/// Create a line segment
pub fn line_segment(start: Point<3>, end: Point<3>) -> Self {
Self {
curve: Curve::Line(Line {
origin: start,
dir: end - start,
}),
vertices: Some([point![0.], point![1.]]),
reverse: false,
}
}

/// Reverse the edge
pub fn reverse(&mut self) {
self.reverse = !self.reverse;
Expand Down

0 comments on commit 7ddb500

Please sign in to comment.