From cae2409c94b11d17643f7c19829e2653d759ff8e Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Thu, 13 Dec 2007 09:45:27 +0000 Subject: Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history. (bzr r4224) --- src/perspective-line.cpp | 72 ++++++------------------------------------------ 1 file changed, 8 insertions(+), 64 deletions(-) (limited to 'src/perspective-line.cpp') diff --git a/src/perspective-line.cpp b/src/perspective-line.cpp index 90857e6d5..051a1d94a 100644 --- a/src/perspective-line.cpp +++ b/src/perspective-line.cpp @@ -12,77 +12,21 @@ */ #include "perspective-line.h" -#include "desktop.h" +#include "persp3d.h" namespace Box3D { -PerspectiveLine::PerspectiveLine (NR::Point const &pt, Box3D::Axis const axis, Perspective3D *perspective) : - Line (pt, *(perspective->get_vanishing_point(axis)), true) +PerspectiveLine::PerspectiveLine (NR::Point const &pt, Proj::Axis const axis, Persp3D *persp) : + Line (pt, persp3d_get_VP(persp, axis).affine(), true) { - g_assert (perspective != NULL); - g_assert (Box3D::is_single_axis_direction (axis)); + g_assert (persp != NULL); - if (perspective->get_vanishing_point(axis)->state == VP_INFINITE) { - this->set_direction(perspective->get_vanishing_point(axis)->v_dir); + if (!persp3d_get_VP(persp, axis).is_finite()) { + Proj::Pt2 vp(persp3d_get_VP(persp, axis)); + this->set_direction(NR::Point(vp[Proj::X], vp[Proj::Y])); } this->vp_dir = axis; - this->persp = perspective; -} - -// This function makes sure not to return NR::Nothing() -// FIXME: How to gracefully handle parallel lines? -NR::Maybe PerspectiveLine::intersect (Line const &line) -{ - NR::Maybe pt = this->Line::intersect(line); - if (!pt) { - Box3D::VanishingPoint vp = *(persp->get_vanishing_point(vp_dir)); - if (vp.state == VP_INFINITE) { - pt = vp; - } else { - pt = NR::Point (0.0, 0.0); // FIXME: Better solution needed - } - } - return pt; -} - -// FIXME: Do we really need two intersection methods? -NR::Point PerspectiveLine::meet(Line const &line) -{ - return *intersect(line); // works since intersect() does not return NR::Nothing() -} - -NR::Point PerspectiveLine::pt_with_given_cross_ratio (NR::Point const &C, NR::Point const &D, double gamma) -{ - if (persp->get_vanishing_point (vp_dir)->is_finite()) { - NR::Point V (*persp->get_vanishing_point (vp_dir)); - return fourth_pt_with_given_cross_ratio (V, C, D, gamma); - } else { - if (fabs (gamma - 1) < epsilon) { - g_warning ("Cannot compute point with given cross ratio.\n"); - return NR::Point (0.0, 0.0); - } - Line line (C, D); - double lambda_C = line.lambda (C); - double lambda_D = line.lambda (D); - return line.point_from_lambda ((lambda_D - gamma * lambda_C) / (1 - gamma)); - } -} - -NR::Maybe PerspectiveLine::intersection_with_viewbox (SPDesktop *desktop) -{ - NR::Rect vb = desktop->get_display_area(); - /* remaining viewbox corners */ - NR::Point ul (vb.min()[NR::X], vb.max()[NR::Y]); - NR::Point lr (vb.max()[NR::X], vb.min()[NR::Y]); - - std::pair e = side_of_intersection (vb.min(), lr, vb.max(), ul, this->pt, this->v_dir); - if (e.first == e.second) { - // perspective line lies outside the canvas - return NR::Nothing(); - } - - Line line (e.first, e.second); - return this->intersect (line); + this->persp = persp; } } // namespace Box3D -- cgit v1.2.3