summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 442e92e)
raw | patch | inline | side by side (parent: 442e92e)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Sun, 23 Mar 2008 20:36:52 +0000 (20:36 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Sun, 23 Mar 2008 20:36:52 +0000 (20:36 +0000) |
src/livarot/Makefile_insert | patch | blob | history | |
src/livarot/MyMath.h | [deleted file] | patch | blob | history |
src/livarot/MySeg.cpp | [deleted file] | patch | blob | history |
src/livarot/MySeg.h | [deleted file] | patch | blob | history |
index 6982d0a980b598ebdde20cc136554bd8455eb835..e4d88efd55d72ba34fa153fa8556b55440e49231 100644 (file)
livarot/int-line.cpp \
livarot/int-line.h \
livarot/LivarotDefs.h \
- livarot/MyMath.h \
- livarot/MySeg.cpp \
- livarot/MySeg.h \
livarot/Path.cpp \
livarot/Path.h \
livarot/PathConversion.cpp \
diff --git a/src/livarot/MyMath.h b/src/livarot/MyMath.h
--- a/src/livarot/MyMath.h
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * MyMath.h
- * nlivarot
- *
- * Created by fred on Wed Jun 18 2003.
- *
- */
-
-#ifndef my_math
-#define my_math
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifdef HAVE_INTTYPES_H
-# include <inttypes.h>
-#else
-# ifdef HAVE_STDINT_H
-# include <stdint.h>
-# endif
-#endif
-
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-
-typedef struct vec2
-{
- double x, y;
-} vec2;
-
-
-typedef struct mat2
-{
- double xx, xy, yx, yy;
-} mat2;
-
-
-typedef struct vec2d
-{
- double x, y;
-} vec2d;
-
-
-typedef struct mat2d
-{
- double xx, xy, yx, yy;
-} mat2d;
-
-
-#define RotCCW(a) {\
- double t = (a).x;\
- (a).x = (a).y;\
- (a).y = -t;\
-}
-
-#define RotCCWTo(a,d) {\
- (d).x = (a).y;\
- (d).y = -(a).x;\
-}
-
-#define RotCW(a) {\
- double t = (a).x;\
- (a).x = -(a).y;\
- (a).y = t;\
-}
-
-#define RotCWTo(a,d) {\
- (d).x = -(a).y;\
- (d).y = (a).x;\
-}
-
-#define Normalize(a) { \
- double _le = (a).x*(a).x+(a).y*(a).y; \
- if ( _le > 0.0001 ) { \
- _le = 1.0 / sqrt(_le); \
- (a).x *= _le; \
- (a).y *= _le; \
- } \
-}
-
-#define L_VEC_Set(a,u,v) { \
- a.x = u; \
- a.y = v; \
-}
-
-
-#define L_VEC_Length(a,l) { \
- l = sqrt(a.x*a.x+a.y*a.y); \
-}
-
-#define L_VEC_Add(a,b,r) { \
- r.x = a.x+b.x; \
- r.y = a.y+b.y; \
-}
-
-#define L_VEC_Sub(a,b,r) { \
- r.x = a.x-b.x; \
- r.y = a.y-b.y; \
-}
-
-#define L_VEC_Mul(a,b,r) { \
- r.x = a.x*b.x; \
- r.y = a.y*b.y; \
-}
-
-#define L_VEC_Div(a,b,r) { \
- r.x = a.x/b.x; \
- r.y = a.y/b.y; \
-}
-
-#define L_VEC_AddMul(a,b,c,r) { \
- r.x = a.x+b.x*c.x; \
- r.y = a.y+b.y*c.y; \
-}
-
-#define L_VEC_SubMul(a,b,c,r) { \
- r.x = a.x-b.x*c.x; \
- r.y = a.y-b.y*c.y; \
-}
-
-
-#define L_VEC_MulC(a,b,r) { \
- r.x = a.x*(b); \
- r.y = a.y*(b); \
-}
-
-#define L_VEC_DivC(a,b,r) { \
- r.x = a.x/(b); \
- r.y = a.y/(b); \
-}
-
-#define L_VEC_AddMulC(a,b,c,r) { \
- r.x = a.x+b.x*c; \
- r.y = a.y+b.y*c; \
-}
-
-#define L_VEC_SubMulC(a,b,c,r) { \
- r.x = a.x-b.x*c; \
- r.y = a.y-b.y*c; \
-}
-
-#define L_VEC_Cmp(a,b) ((fabs(a.y-b.y)<0.0000001)? \
- ((fabs(a.x-b.x)<0.0000001)?0:((a.x > b.x)?1:-1)): \
- ((a.y > b.y)?1:-1))
-
-#define L_VAL_Cmp(a,b) ((fabs(a-b)<0.0000001)?0:((a>b)?1:-1))
-
-#define L_VEC_Normalize(d) { \
- double l=sqrt(d.x*d.x+d.y*d.y); \
- if ( l < 0.00000001 ) { \
- d.x=d.y=0; \
- } else { \
- d.x/=l; \
- d.y/=l; \
- } \
-}
-
-#define L_VEC_Distance(a,b,d) { \
- double dx = a.x-b.x; \
- double dy = a.y-b.y; \
- d = sqrt(dx*dx + dy*dy); \
-}
-
-#define L_VEC_Neg(d) { \
- d.x=d.x; d.y=-d.y; \
-}
-
-#define L_VEC_RotCW(d) { \
- double t=d.x; d.x=d.y; d.y=-t; \
-} \
-
-#define L_VEC_RotCCW(d) { \
- double t=d.x; d.x=-d.y; d.y=t; \
-}
-
-#define L_VAL_Zero(a) ((fabs(a)<0.00000001)?0:((a>0)?1:-1))
-
-#define L_VEC_Cross(a,b,r) { \
- r = a.x*b.x+a.y*b.y; \
-}
-
-#define L_VEC_Dot(a,b,r) { \
- r = a.x*b.y-a.y*b.x; \
-}
-
-
-#define L_MAT(m,a,b) { \
- c[0][0].Set(ica.x); c[0][1].Set(icb.x); c[1][0].Set(ica.y); c[1][1].Set(icb.y); \
-}
-
-#define L_MAT_Set(m,a00,a10,a01,a11) {m.xx = a00; m.xy = a01; m.yx = a10; m.yy = a11;}
-
-#define L_MAT_SetC(m,a,b) {m.xx = a.x; m.xy = b.x; m.yx = a.y; m.yy = b.y;}
-
-#define L_MAT_SetL(m,a,b) {m.xx = a.x; m.xy = a.y;m.yx = b.x; m.yy = b.y;}
-
-#define L_MAT_Init(m) {m.xx=m.xy=m.yx=m.yy=0;}
-
-#define L_MAT_Col(m,no,r) { \
- if ( no == 0 ) { \
- r.x = m.xx; \
- r.y = m.yx; \
- } \
- if ( no == 0 ) { \
- r.x = m.xy; \
- r.y = m.yy; \
- } \
-}
-
-#define L_MAT_Row(m,no,r) { \
- if ( no == 0 ) { \
- r.x = m.xx; \
- r.y = m.xy; \
- } \
- if ( no == 0 ) { \
- r.x = m.yx; \
- r.y = m.yy; \
- } \
-}
-
-#define L_MAT_Det(m,d) {d=m.xx*m.yy-m.xy*m.yx;}
-
-#define L_MAT_Neg(m) {m.xx=-m.xx; m.xy=-m.xy; m.yx=-m.yx; m.yy=-m.yy;}
-
-#define L_MAT_Trs(m) {double t=m.xy; m.xy=m.yx; m.yx=t;}
-
-#define L_MAT_Inv(m) { \
- double d; \
- L_MAT_Det(m,d); \
- m.yx =- m.yx; \
- m.xy =- m.xy; \
- double t=m.xx;m.xx=m.yy;m.yy=t; \
- double inv_d = 1.0/d; \
- m.xx *= inv_d; \
- m.xy *= inv_d; \
- m.yx *= inv_d; \
- m.yy *= inv_d; \
-}
-
-#define L_MAT_Cof(m) { \
- m.yx =- m.yx; \
- m.xy =- m.xy; \
- double t=m.xx; m.xx=m.yy; m.yy=t; \
-}
-
-#define L_MAT_Add(u,v,m) { \
- m.xx=u.xx+v.xx; m.xy=u.xy+v.xy; m.yx=u.yx+v.yx; m.yy=u.yy+v.yy; \
-}
-
-#define L_MAT_Sub(u,v,m) { \
- m.xx=u.xx-v.xx; m.xy=u.xy-v.xy; m.yx=u.yx-v.yx; m.yy=u.yy-v.yy; \
-}
-
-#define L_MAT_Mul(u,v,m) { \
- mat2d r; \
- r.xx = u.xx*v.xx+u.xy*v.yx; \
- r.yx = u.yx*v.xx+u.yy*y.yx; \
- r.xy = u.xx*v.xy+u.xy*v.yy; \
- r.yy = u.yx*v.xy+u.yy*v.yy; \
- m=r; \
-}
-
-#define L_MAT_MulC(u,v,m) { \
- m.xx=u.xx*v; m.xy=u.xy*v; m.yx=u.yx*v; m.yy=u.yy*v; \
-}
-
-#define L_MAT_DivC(u,v,m) { \
- double iv = 1.0/v; \
- m.xx = u.xx*iv; m.xy=u.xy*iv; m.yx=u.yx*iv; m.yy=u.yy*iv; \
-}
-
-#define L_MAT_MulV(m,v,r) { \
- vec2d t; \
- t.x = m.xx*v.x+m.xy*v.y; \
- t.y = m.yx*v.x+m.yy*v.y; \
- r=t; \
-}
-
-#define L_MAT_TMulV(m,v,r) { \
- vec2d t; \
- t.x = m.xx*v.x+m.yx*v.y; \
- t.y = m.xy*v.x+m.yy*v.y; \
- r=t; \
-}
-
-
-
-#endif
diff --git a/src/livarot/MySeg.cpp b/src/livarot/MySeg.cpp
--- a/src/livarot/MySeg.cpp
+++ /dev/null
@@ -1,867 +0,0 @@
-/*
- * MySeg.cpp
- * nlivarot
- *
- * Created by fred on Wed Nov 12 2003.
- * Copyright (c) 2003 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "MySeg.h"
-#include <math.h>
-
-void
-L_SEG::Distance (L_SEG & is, double &di, int mode)
-{
- if (mode == inters_seg_seg)
- {
- double ms, me, os, oe;
-
- vec2d en = is.p;
- L_VEC_Add (en, is.d, en);
-
- Distance (is.p, os, inters_seg_pt);
- Distance (en, oe, inters_seg_pt);
-
- en = p;
- L_VEC_Add (en, d, en);
-
- is.Distance (p, ms, inters_orseg_pt);
- is.Distance (en, me, inters_orseg_pt);
- if (L_VAL_Zero (ms) < 0 || L_VAL_Zero (me) < 0)
- {
- di = 1000000;
- return;
- }
- if (L_VAL_Cmp (oe, os) < 0)
- os = oe;
- if (L_VAL_Cmp (me, ms) < 0)
- ms = me;
- if (L_VAL_Cmp (ms, os) < 0)
- os = ms;
- di = os;
- }
- else if (mode == inters_seg_dmd)
- {
- }
- else if (mode == inters_seg_dr)
- {
- }
-}
-
-void
-L_SEG::Distance (vec2d & iv, double &di, int mode)
-{
- if (L_VAL_Zero (d.x) == 0 && L_VAL_Zero (d.y) == 0)
- {
- L_VEC_Distance (p, iv, di);
- return;
- }
- double dd, sqd;
- vec2d nd = d;
- L_VEC_RotCW (nd);
- L_VEC_Cross (nd, nd, dd);
- sqd = sqrt (dd);
- vec2d diff = iv;
- L_VEC_Sub (diff, p, diff);
- if (mode == inters_dr_pt)
- {
- double cp;
- L_VEC_Cross (diff, nd, cp);
- di = cp / sqd;
- if (di < 0)
- di = -di;
- }
- else if (mode == inters_dmd_pt)
- {
- double cp;
- L_VEC_Cross (diff, d, cp);
- if (cp < 0)
- {
- L_VEC_Distance (p, iv, di);
- return;
- }
- L_VEC_Cross (diff, nd, cp);
- di = cp / sqd;
- if (di < 0)
- di = -di;
- }
- else if (mode == inters_seg_pt)
- {
- double cp;
- L_VEC_Cross (diff, d, cp);
- if (cp < 0)
- {
- L_VEC_Distance (p, iv, di);
- return;
- }
- if (cp > dd)
- {
- vec2d se = p;
- L_VEC_Add (se, d, se);
- L_VEC_Distance (se, iv, di);
- return;
- }
- L_VEC_Cross (diff, nd, cp);
- di = cp / sqd;
- if (di < 0)
- di = -di;
- }
- else if (mode == inters_orseg_pt)
- {
- double cp;
- L_VEC_Cross (diff, d, cp);
- if (cp < 0)
- {
- L_VEC_Distance (p, iv, di);
- L_VEC_Dot (diff, d, cp);
- if (L_VAL_Zero (cp) < 0)
- di = -di;
- return;
- }
- if (cp > dd)
- {
- vec2d se = p;
- L_VEC_Add (se, d, se);
- L_VEC_Distance (se, iv, di);
-
- L_VEC_Dot (diff, d, cp);
- if (cp < 0)
- di = -di;
- return;
- }
- L_VEC_Cross (diff, nd, cp);
- di = cp / sqd;
-// if ( diL_VAL_Zero() < 0 ) di.Neg();
- }
-}
-
-int
-L_SEG::Intersect (L_SEG & iu, L_SEG & iv, int mode)
-{
- double iudd, ivdd;
- L_VEC_Cross (iu.d, iu.d, iudd);
- L_VEC_Cross (iv.d, iv.d, ivdd);
- if (L_VAL_Zero (iudd) <= 0)
- return 0; // cas illicite
- if (L_VAL_Zero (ivdd) <= 0)
- return 0; // cas illicite
-
- vec2d usvs, uevs, usve, ueve;
- L_VEC_Sub (iv.p, iu.p, usvs);
- L_VEC_Sub (usvs, iu.d, uevs);
- L_VEC_Add (usvs, iv.d, usve);
- L_VEC_Sub (usve, iu.d, ueve);
- double usvsl, uevsl, usvel, uevel;
- L_VEC_Cross (usvs, usvs, usvsl);
- L_VEC_Cross (uevs, uevs, uevsl);
- L_VEC_Cross (usve, usve, usvel);
- L_VEC_Cross (ueve, ueve, uevel);
-
- double dd;
- L_VEC_Cross (iu.d, iv.d, dd);
-
- if (L_VAL_Zero (usvsl) <= 0)
- {
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear + inters_a_st + inters_b_st;
- }
- else if (mode == inters_dmd_dmd || mode == inters_seg_dmd
- || mode == inters_seg_seg)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- return inters_colinear + inters_a_st + inters_b_st;
- }
- else
- {
- return inters_a_st + inters_b_st;
- }
- }
- return 0;
- }
- if (L_VAL_Zero (uevsl) <= 0)
- {
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear + inters_a_en + inters_b_st;
- }
- else if (mode == inters_dmd_dmd)
- {
- return inters_colinear + inters_a_en + inters_b_st;
- }
- else if (mode == inters_seg_dmd || mode == inters_seg_seg)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- return inters_a_en + inters_b_st;
- }
- else
- {
- return inters_colinear + inters_a_en + inters_b_st;
- }
- }
- return 0;
- }
- if (L_VAL_Zero (usvel) <= 0)
- {
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear + inters_a_st + inters_b_en;
- }
- else if (mode == inters_dmd_dmd || mode == inters_seg_dmd)
- {
- return inters_colinear + inters_a_st + inters_b_en;
- }
- else if (mode == inters_seg_seg)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- return inters_a_st + inters_b_en;
- }
- else
- {
- return inters_colinear + inters_a_st + inters_b_en;
- }
- }
- return 0;
- }
- if (L_VAL_Zero (uevel) <= 0)
- {
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear + inters_a_en + inters_b_en;
- }
- else if (mode == inters_dmd_dmd || mode == inters_seg_dmd)
- {
- return inters_colinear + inters_a_en + inters_b_en;
- }
- else if (mode == inters_seg_seg)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- return inters_colinear + inters_a_en + inters_b_en;
- }
- else
- {
- return inters_a_en + inters_b_en;
- }
- }
- return 0;
- }
-
- // plus d'extremites en commun a partir de ce point
-
- mat2d m;
- L_MAT_SetC (m, iu.d, iv.d);
- double det;
- L_MAT_Det (m, det);
-
- if (L_VAL_Zero (det) == 0)
- { // ces couillons de vecteurs sont colineaires
- vec2d iudp;
- iudp.x = iu.d.y;
- iudp.y = -iu.d.x;
- double dist;
- L_VEC_Cross (iudp, usvs, dist);
- if (L_VAL_Zero (dist) == 0)
- {
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear;
- }
- else if (mode == inters_dmd_dmd)
- {
- if (L_VAL_Zero (dd) > 0)
- return inters_colinear;
- double ts;
- L_VEC_Cross (iu.d, usvs, ts);
- if (L_VAL_Zero (ts) > 0)
- return inters_colinear;
- return 0;
- }
- else if (mode == inters_seg_dmd)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- double ts;
- L_VEC_Cross (iv.d, uevs, ts);
- if (L_VAL_Zero (ts) < 0)
- return inters_colinear;
- return 0;
- }
- else
- {
- double ts;
- L_VEC_Cross (iv.d, usvs, ts);
- if (L_VAL_Zero (ts) < 0)
- return inters_colinear;
- return 0;
- }
- }
- else if (mode == inters_seg_seg)
- {
- double ts, te;
- L_VEC_Cross (iu.d, usvs, ts);
- L_VEC_Cross (iu.d, uevs, te);
- if (L_VAL_Zero (ts) > 0 && L_VAL_Zero (te) < 0)
- return inters_colinear;
- L_VEC_Cross (iu.d, usve, ts);
- L_VEC_Cross (iu.d, ueve, te);
- if (L_VAL_Zero (ts) > 0 && L_VAL_Zero (te) < 0)
- return inters_colinear;
- L_VEC_Cross (iv.d, usvs, ts);
- L_VEC_Cross (iv.d, usve, te);
- if (L_VAL_Zero (ts) < 0 && L_VAL_Zero (te) > 0)
- return inters_colinear;
- L_VEC_Cross (iv.d, uevs, ts);
- L_VEC_Cross (iv.d, ueve, te);
- if (L_VAL_Zero (ts) < 0 && L_VAL_Zero (te) > 0)
- return inters_colinear;
- return 0;
- }
- }
- else
- {
- return 0; // paralleles
- }
- }
-
- // plus de colinearite ni d'extremites en commun
- L_MAT_Inv (m);
- vec2d res;
- L_MAT_MulV (m, usvs, res);
-
- if (mode == inters_dr_dr)
- {
- return inters_a_mi + inters_b_mi;
- }
- else if (mode == inters_dmd_dr)
- {
- int i = L_VAL_Zero (res.x);
- if (i == 0)
- return inters_a_st + inters_b_mi;
- if (i > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_dr)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- if (i == 0)
- return inters_a_st + inters_b_mi;
- if (j == 0)
- return inters_a_en + inters_b_mi;
- if (i > 0 && j < 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_dmd_dmd)
- {
- int i = L_VAL_Zero (res.x);
- int j = -(L_VAL_Zero (res.y));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && j > 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && i > 0)
- return inters_a_mi + inters_b_st;
- if (i > 0 && j > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_dmd)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- int k = -(L_VAL_Zero (res.y));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && k > 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && k > 0)
- return inters_a_en + inters_b_mi;
- if (i > 0 && j < 0 && k == 0)
- return inters_a_mi + inters_b_st;
- if (i > 0 && j < 0 && k > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_seg)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- int k = -(L_VAL_Zero (res.y));
- int l = -(L_VAL_Cmp (res.y, 1));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && k > 0 && l < 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && k > 0 && l < 0)
- return inters_a_en + inters_b_mi;
- if (k == 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_st;
- if (l == 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_en;
- if (k > 0 && l < 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
-
- return 0;
-}
-
-int
-L_SEG::Intersect (L_SEG & iu, L_SEG & iv, vec2d & at, int mode)
-{
- double iudd, ivdd;
- L_VEC_Cross (iu.d, iu.d, iudd);
- L_VEC_Cross (iv.d, iv.d, ivdd);
- if (L_VAL_Zero (iudd) <= 0)
- return 0; // cas illicite
- if (L_VAL_Zero (ivdd) <= 0)
- return 0; // cas illicite
-
- vec2d usvs, uevs, usve, ueve;
- L_VEC_Sub (iv.p, iu.p, usvs);
- L_VEC_Sub (usvs, iu.d, uevs);
- L_VEC_Add (usvs, iv.d, usve);
- L_VEC_Sub (usve, iu.d, ueve);
- double usvsl, uevsl, usvel, uevel;
- L_VEC_Cross (usvs, usvs, usvsl);
- L_VEC_Cross (uevs, uevs, uevsl);
- L_VEC_Cross (usve, usve, usvel);
- L_VEC_Cross (ueve, ueve, uevel);
-
- double dd;
- L_VEC_Cross (iu.d, iv.d, dd);
-
- if (L_VAL_Zero (usvsl) <= 0)
- {
- at = iu.p;
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear + inters_a_st + inters_b_st;
- }
- else if (mode == inters_dmd_dmd || mode == inters_seg_dmd
- || mode == inters_seg_seg)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- return inters_colinear + inters_a_st + inters_b_st;
- }
- else
- {
- return inters_a_st + inters_b_st;
- }
- }
- return 0;
- }
- if (L_VAL_Zero (uevsl) <= 0)
- {
- at = iv.p;
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear + inters_a_en + inters_b_st;
- }
- else if (mode == inters_dmd_dmd)
- {
- return inters_colinear + inters_a_en + inters_b_st;
- }
- else if (mode == inters_seg_dmd || mode == inters_seg_seg)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- return inters_a_en + inters_b_st;
- }
- else
- {
- return inters_colinear + inters_a_en + inters_b_st;
- }
- }
- return 0;
- }
- if (L_VAL_Zero (usvel) <= 0)
- {
- at = iu.p;
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear + inters_a_st + inters_b_en;
- }
- else if (mode == inters_dmd_dmd || mode == inters_seg_dmd)
- {
- return inters_colinear + inters_a_st + inters_b_en;
- }
- else if (mode == inters_seg_seg)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- return inters_a_st + inters_b_en;
- }
- else
- {
- return inters_colinear + inters_a_st + inters_b_en;
- }
- }
- return 0;
- }
- if (L_VAL_Zero (uevel) <= 0)
- {
- at = iu.p;
- L_VEC_Add (at, iu.d, at);
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear + inters_a_en + inters_b_en;
- }
- else if (mode == inters_dmd_dmd || mode == inters_seg_dmd)
- {
- return inters_colinear + inters_a_en + inters_b_en;
- }
- else if (mode == inters_seg_seg)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- return inters_colinear + inters_a_en + inters_b_en;
- }
- else
- {
- return inters_a_en + inters_b_en;
- }
- }
- return 0;
- }
-
- // plus d'extremites en commun a partir de ce point
-
- mat2d m;
- L_MAT_SetC (m, iu.d, iv.d);
- double det;
- L_MAT_Det (m, det);
-
- if (L_VAL_Zero (det) == 0)
- { // ces couillons de vecteurs sont colineaires
- vec2d iudp;
- iudp.x = iu.d.y;
- iudp.y = -iu.d.x;
- double dist;
- L_VEC_Cross (iudp, usvs, dist);
- if (L_VAL_Zero (dist) == 0)
- {
- if (mode == inters_dr_dr || mode == inters_dmd_dr
- || mode == inters_seg_dr)
- {
- return inters_colinear;
- }
- else if (mode == inters_dmd_dmd)
- {
- if (L_VAL_Zero (dd) > 0)
- return inters_colinear;
- double ts;
- L_VEC_Cross (iu.d, usvs, ts);
- if (L_VAL_Zero (ts) > 0)
- return inters_colinear;
- return 0;
- }
- else if (mode == inters_seg_dmd)
- {
- if (L_VAL_Zero (dd) > 0)
- {
- double ts;
- L_VEC_Cross (iv.d, uevs, ts);
- if (L_VAL_Zero (ts) < 0)
- return inters_colinear;
- return 0;
- }
- else
- {
- double ts;
- L_VEC_Cross (iv.d, usvs, ts);
- if (L_VAL_Zero (ts) < 0)
- return inters_colinear;
- return 0;
- }
- }
- else if (mode == inters_seg_seg)
- {
- double ts, te;
- L_VEC_Cross (iu.d, usvs, ts);
- L_VEC_Cross (iu.d, uevs, te);
- if (L_VAL_Zero (ts) > 0 && L_VAL_Zero (te) < 0)
- return inters_colinear;
- L_VEC_Cross (iu.d, usve, ts);
- L_VEC_Cross (iu.d, ueve, te);
- if (L_VAL_Zero (ts) > 0 && L_VAL_Zero (te) < 0)
- return inters_colinear;
- L_VEC_Cross (iv.d, usvs, ts);
- L_VEC_Cross (iv.d, usve, te);
- if (L_VAL_Zero (ts) < 0 && L_VAL_Zero (te) > 0)
- return inters_colinear;
- L_VEC_Cross (iv.d, uevs, ts);
- L_VEC_Cross (iv.d, ueve, te);
- if (L_VAL_Zero (ts) < 0 && L_VAL_Zero (te) > 0)
- return inters_colinear;
- return 0;
- }
- }
- else
- {
- return 0; // paralleles
- }
- }
-
- // plus de colinearite ni d'extremites en commun
- L_MAT_Inv (m);
- vec2d res;
- L_MAT_MulV (m, usvs, res);
-
- // l'intersection
- L_VEC_MulC (iu.d, res.x, at);
- L_VEC_Add (at, iu.p, at);
-
- if (mode == inters_dr_dr)
- {
- return inters_a_mi + inters_b_mi;
- }
- else if (mode == inters_dmd_dr)
- {
- int i = L_VAL_Zero (res.x);
- if (i == 0)
- return inters_a_st + inters_b_mi;
- if (i > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_dr)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- if (i == 0)
- return inters_a_st + inters_b_mi;
- if (j == 0)
- return inters_a_en + inters_b_mi;
- if (i > 0 && j < 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_dmd_dmd)
- {
- int i = L_VAL_Zero (res.x);
- int j = -(L_VAL_Zero (res.y));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && j > 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && i > 0)
- return inters_a_mi + inters_b_st;
- if (i > 0 && j > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_dmd)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- int k = -(L_VAL_Zero (res.y));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && k > 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && k > 0)
- return inters_a_en + inters_b_mi;
- if (i > 0 && j < 0 && k == 0)
- return inters_a_mi + inters_b_st;
- if (i > 0 && j < 0 && k > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_seg)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- int k = -(L_VAL_Zero (res.y)); // la coordonnée sur iv est inversee
- int l = -(L_VAL_Cmp (res.y, -1));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && k > 0 && l < 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && k > 0 && l < 0)
- return inters_a_en + inters_b_mi;
- if (k == 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_st;
- if (l == 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_en;
- if (k > 0 && l < 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
-
- return 0;
-}
-
-int
-L_SEG::IntersectGeneral (L_SEG & iu, L_SEG & iv, vec2d & at, int mode)
-{
-
- vec2d usvs;
- L_VEC_Sub (iv.p, iu.p, usvs);
-
- double dd;
- L_VEC_Cross (iu.d, iv.d, dd);
-
-
- mat2d m;
- L_MAT_SetC (m, iu.d, iv.d);
- double det;
- L_MAT_Det (m, det);
-
- if (L_VAL_Zero (det))
- { // ces couillons de vecteurs sont colineaires
- return 0; // paralleles
- }
-
- // plus de colinearite ni d'extremites en commun
- L_MAT_Inv (m);
- vec2d res;
- L_MAT_MulV (m, usvs, res);
-
- // l'intersection
- L_VEC_MulC (iu.d, res.x, at);
- L_VEC_Add (at, iu.p, at);
-
- if (mode == inters_dr_dr)
- {
- return inters_a_mi + inters_b_mi;
- }
- else if (mode == inters_dmd_dr)
- {
- int i = L_VAL_Zero (res.x);
- if (i == 0)
- return inters_a_st + inters_b_mi;
- if (i > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_dr)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- if (i == 0)
- return inters_a_st + inters_b_mi;
- if (j == 0)
- return inters_a_en + inters_b_mi;
- if (i > 0 && j < 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_dmd_dmd)
- {
- int i = L_VAL_Zero (res.x);
- int j = -(L_VAL_Zero (res.y));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && j > 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && i > 0)
- return inters_a_mi + inters_b_st;
- if (i > 0 && j > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_dmd)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- int k = -(L_VAL_Zero (res.y));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && k > 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && k > 0)
- return inters_a_en + inters_b_mi;
- if (i > 0 && j < 0 && k == 0)
- return inters_a_mi + inters_b_st;
- if (i > 0 && j < 0 && k > 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
- else if (mode == inters_seg_seg)
- {
- int i = L_VAL_Zero (res.x);
- int j = L_VAL_Cmp (res.x, 1);
- int k = -(L_VAL_Zero (res.y)); // la coordonnée sur iv est inversee
- int l = -(L_VAL_Cmp (res.y, -1));
- // nota : i=0 et j=0 a ete elimine au debut
- if (i == 0 && k > 0 && l < 0)
- return inters_a_st + inters_b_mi;
- if (j == 0 && k > 0 && l < 0)
- return inters_a_en + inters_b_mi;
- if (k == 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_st;
- if (l == 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_en;
- if (k > 0 && l < 0 && i > 0 && j < 0)
- return inters_a_mi + inters_b_mi;
- return 0;
- }
-
- return 0;
-}
-
-int
-L_SEG::Contains (vec2d & pos, int mode)
-{
- vec2d sp, ep;
- L_VEC_Sub (pos, p, sp);
- L_VEC_Sub (sp, d, ep);
- double spl, epl;
- L_VEC_Cross (sp, sp, spl);
- L_VEC_Cross (ep, ep, epl);
- if (L_VAL_Zero (spl) == 0)
- {
- if (mode == inters_dr_pt)
- return inters_a_mi;
- return inters_a_st;
- }
- if (L_VAL_Zero (epl) == 0)
- {
- if (mode == inters_dr_pt || mode == inters_dmd_pt)
- return inters_a_mi;
- return inters_a_en;
- }
-
- vec2d perp = d;
- L_VEC_RotCW (perp);
-
- double dd, ps;
- L_VEC_Cross (d, d, dd);
- L_VEC_Cross (perp, sp, ps);
- if (L_VAL_Zero (ps) == 0)
- { // sur la droite
- if (mode == inters_dr_pt)
- return inters_a_mi;
- L_VEC_Cross (d, sp, ps);
- // ps != 0 car le cas est traité avant
- if (mode == inters_dmd_pt)
- {
- if (L_VAL_Zero (ps) > 0)
- {
- return inters_a_mi;
- }
- }
- else
- {
- if (L_VAL_Zero (ps) > 0)
- {
- if (L_VAL_Cmp (ps, dd) < 0)
- {
- return inters_a_mi;
- }
- }
- }
- }
-
- return 0;
-}
diff --git a/src/livarot/MySeg.h b/src/livarot/MySeg.h
--- a/src/livarot/MySeg.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * MySeg.h
- * nlivarot
- *
- * Created by fred on Wed Nov 12 2003.
- *
- */
-
-#ifndef my_math_seg
-#define my_math_seg
-
-#include "MyMath.h"
-
-// codes for the intersections computations
-// pt = point
-// seg = segment
-// dmd = half line
-// dr = infinite line
-enum
-{
- inters_seg_seg, // intersection between 2 segments
- inters_seg_dmd, // intersection between one segment (parameter no 1) and one half-line (parameter no 2)
- inters_seg_dr, // ....
- inters_dmd_dmd,
- inters_dmd_dr,
- inters_dr_dr,
-
- inters_seg_pt, // "intersection" between segment and point= "does the segment contain the point?"
- inters_dmd_pt,
- inters_dr_pt,
-
- inters_orseg_pt // don't use
-};
-
-// return codes for the intersection computations; build as a concatenation of
-// _a = first parameter
-// _b = second parameter
-// _st = start of the segment/half-line (lines don't have starts)
-// _en = end of thz segment (half-lines and lines don't have ends)
-// _mi = inside of the segment/half-line/line
-// _colinear = this flag is set if the intersection of the 2 parameter is more than a point
-// the first 2 bits of the return code contain the position of the intersection on the first parameter (_st, _mi or _en)
-// the next 2 bits of the return code contain the position of the intersection on the second parameter (_st, _mi or _en)
-// the 5th bit is set if the parameters are colinear
-enum
-{
- inters_a_st = 1,
- inters_a_mi = 2,
- inters_a_en = 3,
- inters_b_st = 4,
- inters_b_mi = 8,
- inters_b_en = 12,
- inters_colinear = 16
-};
-
-
-//
-// a class to describe a segment: defined by its startpoint p and its direction d
-// if the object is considered as a segment: p+xd, where x ranges from 0 to 1
-// if the object is considered as an half-line, the length of the direction vector doesn't matter:
-// p+xd, where x ranges from 0 to +infinity
-// if the object is considered as a line: p+xd, where x ranges from -infinity to +infinity
-//
-class L_SEG
-{
-public:
- vec2d p, d;
-
- // constructors
- L_SEG (vec2d & st, vec2d & dir):p (st), d (dir)
- {
- }; // by default, you give one startpoint and one direction
- L_SEG (void)
- {
- };
- virtual ~L_SEG (void)
- {
- };
-
- // assignations
- void Set (L_SEG * s)
- {
- p = s->p;
- d = s->d;
- };
- void Set (L_SEG & s)
- {
- p = s.p;
- d = s.d;
- };
- // 2 specific assignations:
- // assignation where you give the startpoint and the direction (like in the constructor):
- void SetSD (vec2d & st, vec2d & dir)
- {
- p = st;
- d = dir;
- };
- // assignation where you give the startpoint and the endpoint:
- void SetSE (vec2d & st, vec2d & en)
- {
- p = st;
- d.x = en.x - st.x;
- d.y = en.y - st.y;
- };
-
- // reverses the segment
- void Rev (void)
- {
- p.x += d.x;
- p.y += d.y;
- d.x = -d.x;
- d.y = -d.y;
- };
- // transitibve version: the reversed segment is stored in s
- void Rev (L_SEG & s)
- {
- s.p.x = p.x + d.x;
- s.p.y = p.y + d.y;
- s.d.x = -d.x;
- s.d.y = -d.y;
- };
-
- // distance of the point iv to the segment/half-line/line
- // the mode parameter specifies how the caller instance should be handled:
- // inters_seg_pt : segment
- // inters_dmd_pt : half-line
- // inters_dr_pt : line
- void Distance (vec2d & iv, double &d, int mode = inters_dr_pt);
- // distance between 2 segments
- // mode parameter specifies how the segments have to be treated (just like above)
- void Distance (L_SEG & is, double &d, int mode = inters_seg_seg);
-
- // tests if the segment contains the point pos
- // mode is as in the Distance function
- int Contains (vec2d & pos, int mode);
-
- // intersection between 2 lines/half-lines/segments
- // mode specifies how the L_SEG instances have to be considered; codes at the beginning of this file
- // the "at" parameter stores the intersection point, if it exists and is unique
- static int Intersect (L_SEG & iu, L_SEG & iv, int mode);
- static int Intersect (L_SEG & iu, L_SEG & iv, vec2d & at, int mode);
- // specific version, when you can garantuee the colinearity case won't occur
- static int IntersectGeneral (L_SEG & iu, L_SEG & iv, vec2d & at, int mode);
-};
-
-
-#endif