blob: ca94544a13e2ac6da8bcd9f8d673bd308db9d978 [file] [log] [blame]
caryclark@google.comc6825902012-02-03 22:07:47 +00001#include "CurveIntersection.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00002#include "LineUtilities.h"
3
4bool implicitLine(const _Line& line, double& slope, double& axisIntercept) {
caryclark@google.comc6825902012-02-03 22:07:47 +00005 _Point delta;
6 tangent(line, delta);
7 bool moreHorizontal = fabs(delta.x) > fabs(delta.y);
caryclark@google.com27accef2012-01-25 18:57:23 +00008 if (moreHorizontal) {
caryclark@google.comc6825902012-02-03 22:07:47 +00009 slope = delta.y / delta.x;
caryclark@google.com27accef2012-01-25 18:57:23 +000010 axisIntercept = line[0].y - slope * line[0].x;
11 } else {
caryclark@google.comc6825902012-02-03 22:07:47 +000012 slope = delta.x / delta.y;
caryclark@google.com27accef2012-01-25 18:57:23 +000013 axisIntercept = line[0].x - slope * line[0].y;
14 }
15 return moreHorizontal;
16}
17
18int reduceOrder(const _Line& line, _Line& reduced) {
19 reduced[0] = line[0];
20 int different = line[0] != line[1];
21 reduced[1] = line[different];
22 return 1 + different;
23}
caryclark@google.com6680fb12012-02-07 22:10:51 +000024
25void sub_divide(const _Line& line, double t1, double t2, _Line& dst) {
26 _Point delta;
27 tangent(line, delta);
28 dst[0].x = line[0].x - t1 * delta.x;
29 dst[0].y = line[0].y - t1 * delta.y;
30 dst[1].x = line[0].x - t2 * delta.x;
31 dst[1].y = line[0].y - t2 * delta.y;
32}
caryclark@google.comfa0588f2012-04-26 21:01:06 +000033
34// may have this below somewhere else already:
35// copying here because I thought it was clever
36
37// Copyright 2001, softSurfer (www.softsurfer.com)
38// This code may be freely used and modified for any purpose
39// providing that this copyright notice is included with it.
40// SoftSurfer makes no warranty for this code, and cannot be held
41// liable for any real or imagined damage resulting from its use.
42// Users of this code must verify correctness for their application.
43
44// Assume that a class is already given for the object:
45// Point with coordinates {float x, y;}
46//===================================================================
47
48// isLeft(): tests if a point is Left|On|Right of an infinite line.
49// Input: three points P0, P1, and P2
50// Return: >0 for P2 left of the line through P0 and P1
51// =0 for P2 on the line
52// <0 for P2 right of the line
53// See: the January 2001 Algorithm on Area of Triangles
caryclark@google.coma3f05fa2012-06-01 17:44:28 +000054#if 0
caryclark@google.comfa0588f2012-04-26 21:01:06 +000055float isLeft( _Point P0, _Point P1, _Point P2 )
56{
caryclark@google.com1577e8f2012-05-22 17:01:14 +000057 return (float) ((P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y));
caryclark@google.comfa0588f2012-04-26 21:01:06 +000058}
caryclark@google.coma3f05fa2012-06-01 17:44:28 +000059#endif
60