1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_BezierUtils_h_
8 #define mozilla_BezierUtils_h_
10 #include "mozilla/gfx/Point.h"
11 #include "mozilla/gfx/Types.h"
16 // Control points for bezier curve
19 // +-----___---+ mPoints[3]
37 // Calculate a point or it's differential of a bezier curve formed by
38 // aBezier and parameter t.
40 // GetBezierPoint = P(t)
41 // GetBezierDifferential = P'(t)
42 // GetBezierDifferential2 = P''(t)
45 // +-----___---+ mPoints[3]
59 Point
GetBezierPoint(const Bezier
& aBezier
, Float t
);
60 Point
GetBezierDifferential(const Bezier
& aBezier
, Float t
);
61 Point
GetBezierDifferential2(const Bezier
& aBezier
, Float t
);
63 // Calculate length of a simple bezier curve formed by aBezier and range [a, b].
64 Float
GetBezierLength(const Bezier
& aBezier
, Float a
, Float b
);
66 // Split bezier curve formed by aBezier into [0,t1], [t1,t2], [t2,1] parts, and
67 // stores control points for [t1,t2] to aSubBezier.
83 void GetSubBezier(Bezier
* aSubBezier
, const Bezier
& aBezier
, Float t1
,
86 // Find a nearest point on bezier curve formed by aBezier to a point aTarget.
87 // aInitialT is a hint to find the parameter t for the nearest point.
88 // If aT is non-null, parameter for the nearest point is stored to *aT.
89 // This function expects a bezier curve to be an approximation of elliptic arc.
90 // Otherwise it will return wrong point.
97 // / nearest point = P(t = *aT)
107 Point
FindBezierNearestPoint(const Bezier
& aBezier
, const Point
& aTarget
,
108 Float aInitialT
, Float
* aT
= nullptr);
110 // Calculate control points for a bezier curve that is an approximation of
114 // |<----------------->|
116 // aCornerPoint| mPoints[2] |
117 // -------------+-------+-----___---+ mPoints[3]
122 // aCornerSize.height | mPoints[1] + |
131 void GetBezierPointsForCorner(Bezier
* aBezier
, mozilla::Corner aCorner
,
132 const Point
& aCornerPoint
,
133 const Size
& aCornerSize
);
135 // Calculate the approximate length of a quarter elliptic arc formed by radii
139 // |<----------------->|
141 // ---+-------------___---+
155 Float
GetQuarterEllipticArcLength(Float a
, Float b
);
157 // Calculate the distance between an elliptic arc formed by (origin, width,
158 // height), and a point P, along a line formed by |P + n * normal|.
159 // P should be outside of the ellipse, and the line should cross with the
160 // ellipse twice at n > 0 points.
163 // |<----------------->|
165 // -----------+-------------___---+
179 Float
CalculateDistanceToEllipticArc(const Point
& P
, const Point
& normal
,
180 const Point
& origin
, Float width
,
184 } // namespace mozilla
186 #endif /* mozilla_BezierUtils_h_ */