Hey all, just getting started with Swift and running into this issue where, on Textfields with bindings, the first character is always placed ahead of the cursor.
The fix was to upgrade MacOS from 10.15.5 to 10.15.6.
/** | |
* Get an arc (circle segment) between two points. | |
* @param x0 The x-coordinate of the arc's starting point. | |
* @param y0 The y-coordinate of the arc's starting point. | |
* @param a0 The angle in radians of the arc's starting point. | |
* @param x1 The x-coordinate of the arc's ending point. | |
* @param y1 The y-coordinate of the arc's ending point. | |
* @param a1 The angle in radians of the arc's ending point. | |
* @param r The radius of the circle. | |
* @param flip Whether to flip the segment. |
export function remap<P, T>( | |
obj: { [key: string]: T }, | |
fn: (value: T, index: number) => P | |
): { [key: string]: P } { | |
return Object.fromEntries( | |
Object.entries(obj).map(([id, value], index) => [id, fn(value, index)]) | |
) | |
} |
export type RayOptions = { | |
max?: number | |
min?: number | |
start?: number | |
} | |
/** | |
* Casts a ray in a given direction and check if it hits something. | |
* @param from - [x, y] |
export function castRay<T = any>( | |
from: number[], | |
direction: number[], | |
hitTest: (info: { | |
point: number[] | |
distance: number | |
position: number[] | |
positions: number[][] | |
}) => T, |
function getScreenFrame(el: HTMLElement) { | |
var rect = el.getBoundingClientRect(), | |
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, | |
scrollTop = window.pageYOffset || document.documentElement.scrollTop | |
const x = rect.left + scrollLeft, | |
y = rect.top + scrollTop, | |
w = rect.width, | |
h = rect.height |
// Adapted from https://github.com/w8r/bezier-intersect | |
/** | |
* Get the point(s) at which a line segment intersects a cubic bezier curve. | |
* @param p0x The x-coordinate of the curve's starting point. | |
* @param p0y The y-coordinate of the curve's starting point. | |
* @param p1x The x-coordinate of the curve's first control point. | |
* @param p1y The y-coordinate of the curve's first control point. | |
* @param p2x The x-coordinate of the curve's second control point. | |
* @param p2y The y-coordinate of the curve's second control point. |
function getSegmentCircleIntersections( | |
cx: number, | |
cy: number, | |
r: number, | |
x0: number, | |
y0: number, | |
x1: number, | |
y1: number | |
) { | |
var b: number, |
function getSegmentSegmentIntersection( | |
x0: number, | |
y0: number, | |
x1: number, | |
y1: number, | |
x2: number, | |
y2: number, | |
x3: number, | |
y3: number | |
) { |
/** | |
* Get the intersection points between a line segment and a rectangle with rounded corners. | |
* @param x0 The x-axis coordinate of the segment's starting point. | |
* @param y0 The y-axis coordinate of ththe segment's ending point. | |
* @param x1 The delta-x of the ray. | |
* @param y1 The delta-y of the ray. | |
* @param x The x-axis coordinate of the rectangle. | |
* @param y The y-axis coordinate of the rectangle. | |
* @param w The width of the rectangle. |