Fix more random silly bugs; a basic monotone polygon partitions correctly now
This commit is contained in:
parent
ffd167a342
commit
0468bbcc24
|
@ -9,4 +9,6 @@ crate-type = ["dylib", "rlib"]
|
|||
|
||||
[dependencies]
|
||||
bit-vec = "0.4"
|
||||
env_logger = "0.4"
|
||||
euclid = "0.15"
|
||||
log = "0.3"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// partitionfinder/capi.rs
|
||||
|
||||
use env_logger;
|
||||
use partitioner::Partitioner;
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
|
@ -48,3 +49,8 @@ pub unsafe extern fn pf_partitioner_bezieroids<'a>(partitioner: *mut Partitioner
|
|||
}
|
||||
bezieroids.as_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn pf_init_env_logger() -> u32 {
|
||||
env_logger::init().is_ok() as u32
|
||||
}
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
// Needed to work around a problem with `heapsize`
|
||||
extern crate alloc_jemalloc;
|
||||
extern crate bit_vec;
|
||||
extern crate env_logger;
|
||||
extern crate euclid;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use euclid::Point2D;
|
||||
use std::u32;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use bit_vec::BitVec;
|
||||
use euclid::Point2D;
|
||||
use geometry;
|
||||
use log::LogLevel;
|
||||
use std::collections::BinaryHeap;
|
||||
use std::cmp::{self, Ordering};
|
||||
use std::u32;
|
||||
|
@ -72,6 +73,17 @@ impl<'a> Partitioner<'a> {
|
|||
return true
|
||||
}
|
||||
|
||||
debug!("processing point {}: {:?}",
|
||||
point.endpoint_index,
|
||||
self.endpoints[point.endpoint_index as usize].position);
|
||||
|
||||
if log_enabled!(LogLevel::Debug) {
|
||||
debug!("... active edges:");
|
||||
for (active_edge_index, active_edge) in self.active_edges.iter().enumerate() {
|
||||
debug!("... ... edge {}: {:?}", active_edge_index, active_edge);
|
||||
}
|
||||
}
|
||||
|
||||
self.mark_point_as_visited(&point);
|
||||
|
||||
let matching_active_edges = self.find_right_point_in_active_edge_list(point.endpoint_index);
|
||||
|
@ -100,6 +112,8 @@ impl<'a> Partitioner<'a> {
|
|||
}
|
||||
|
||||
fn process_min_endpoint(&mut self, endpoint_index: u32) {
|
||||
debug!("... MIN point");
|
||||
|
||||
let next_active_edge_index = self.find_point_between_active_edges(endpoint_index);
|
||||
|
||||
let endpoint = &self.endpoints[endpoint_index as usize];
|
||||
|
@ -123,6 +137,8 @@ impl<'a> Partitioner<'a> {
|
|||
}
|
||||
|
||||
fn process_regular_endpoint(&mut self, endpoint_index: u32, active_edge_index: u32) {
|
||||
debug!("... REGULAR point: active edge {}", active_edge_index);
|
||||
|
||||
let endpoint = &self.endpoints[endpoint_index as usize];
|
||||
if self.should_fill_below_active_edge(active_edge_index) {
|
||||
self.emit_bezieroid_below(active_edge_index, endpoint.position.x)
|
||||
|
@ -155,6 +171,8 @@ impl<'a> Partitioner<'a> {
|
|||
}
|
||||
|
||||
fn process_max_endpoint(&mut self, endpoint_index: u32, active_edge_indices: [u32; 2]) {
|
||||
debug!("... MAX point: active edges {:?}", active_edge_indices);
|
||||
|
||||
debug_assert!(active_edge_indices[0] < active_edge_indices[1],
|
||||
"Matching active edge indices in wrong order when processing MAX point");
|
||||
|
||||
|
@ -328,7 +346,8 @@ impl<'a> Partitioner<'a> {
|
|||
let prev_point = self.create_point_from_endpoint(self.prev_endpoint_of(endpoint_index));
|
||||
let next_point = self.create_point_from_endpoint(self.next_endpoint_of(endpoint_index));
|
||||
|
||||
match (prev_point.cmp(&point), next_point.cmp(&point)) {
|
||||
// Remember to reverse, because the comparison is reversed (as the heap is a max-heap).
|
||||
match (prev_point.cmp(&point).reverse(), next_point.cmp(&point).reverse()) {
|
||||
(Ordering::Less, Ordering::Less) => EndpointClass::Max,
|
||||
(Ordering::Less, _) | (_, Ordering::Less) => EndpointClass::Regular,
|
||||
(_, _) => EndpointClass::Min,
|
||||
|
@ -594,15 +613,16 @@ impl Eq for Point {}
|
|||
impl PartialOrd for Point {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Point) -> Option<Ordering> {
|
||||
match self.position.x.partial_cmp(&other.position.x) {
|
||||
// Reverse, because `std::collections::BinaryHeap` is a *max*-heap!
|
||||
match other.position.x.partial_cmp(&self.position.x) {
|
||||
None | Some(Ordering::Equal) => {}
|
||||
Some(ordering) => return Some(ordering),
|
||||
}
|
||||
match self.position.y.partial_cmp(&other.position.y) {
|
||||
match other.position.y.partial_cmp(&self.position.y) {
|
||||
None | Some(Ordering::Equal) => {}
|
||||
Some(ordering) => return Some(ordering),
|
||||
}
|
||||
self.endpoint_index.partial_cmp(&other.endpoint_index)
|
||||
other.endpoint_index.partial_cmp(&self.endpoint_index)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,8 @@ void pf_partitioner_partition(pf_partitioner_t *partitioner,
|
|||
const pf_bezieroid_t *pf_partitioner_bezieroids(pf_partitioner_t *partitioner,
|
||||
uint32_t *out_bezieroid_count);
|
||||
|
||||
uint32_t pf_init_env_logger();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue