Skip to content

Commit a823357

Browse files
Mark color stuff as done for now...
1 parent c8b3218 commit a823357

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

diplomat/wx_gui/probability_displayer.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,48 +117,66 @@ def apca_contrast(fg_color, bg_color):
117117
return np.where(np.abs(s_apc) < 0.1, 0.0, np.where(s_apc < 0, (s_apc - 0.027) * 100, (s_apc + 0.027) * 100))
118118

119119

120-
def circle_line_intersection(circle, line):
121-
pass
120+
def circle_line_intersection(circle_center, radius, point_a, point_b):
121+
# Place circle at center...
122+
point_a = point_a - circle_center
123+
point_b = point_b - circle_center
124+
125+
# Params...
126+
dx = point_a[0] - point_b[0]
127+
dy = point_a[1] - point_b[1]
128+
dr = np.sqrt(dx * dx + dy * dy)
129+
determ = point_a[0] * point_b[1] - point_a[1] * point_b[0]
130+
131+
discrim = dr * dr * radius * radius - determ
132+
sgn = lambda x: np.where(x < 0, -1, 1)
133+
134+
discrim_rt = np.sqrt(discrim)
135+
136+
p0 = np.stack([
137+
determ * dy - sgn(dy) * dx * discrim_rt,
138+
-determ * dx - np.abs(dy) * discrim_rt
139+
])
140+
p1 = np.stack([
141+
determ * dy + sgn(dy) * dx * discrim_rt,
142+
-determ * dx + np.abs(dy) * discrim_rt
143+
])
144+
145+
return (
146+
np.where(discrim >= 0, p0, np.nan),
147+
np.where(discrim >= 0, p1, np.nan)
148+
)
122149

123150

151+
# TODO: Finish and enable eventually...
124152
def contrastify_color(fg_color, bg_color, distance: float, as_int8: bool = False):
125153
fg_color = linear_rgb_to_oklab(srgb_to_linear_rgb(fg_color, as_int8))
126154
bg_color = linear_rgb_to_oklab(srgb_to_linear_rgb(fg_color, as_int8))
127155
initial_distance_sq = np.sum((fg_color - bg_color) ** 2, -1)
128156

129-
print(fg_color, bg_color)
130-
print(np.sqrt(initial_distance_sq))
131-
132157
# We want the plane on which the hue stays the same (same angle, any lightness)
133158
plane_norm_vec = np.zeros(fg_color.shape)
134159
plane_norm_vec[..., 1] = -fg_color[..., 2]
135160
plane_norm_vec[..., 2] = fg_color[..., 1]
136161
# Normalize the vector...
137162
plane_norm_vec /= np.sqrt(np.dot(plane_norm_vec, plane_norm_vec))
138163

139-
print(plane_norm_vec)
140-
141164
# Project background point onto the plane...
142165
bg_from_plane_delta = np.dot(bg_color, plane_norm_vec)
143166
nearest_bg_point_on_plane = bg_color - bg_from_plane_delta * plane_norm_vec
144167
remaining_distance = np.sqrt(distance * distance - bg_from_plane_delta * bg_from_plane_delta)
145-
print(bg_from_plane_delta, nearest_bg_point_on_plane)
146168

147169
fg_bg_delta = fg_color - nearest_bg_point_on_plane
148170
fg_to_bg_dist = np.sqrt(np.dot(fg_bg_delta, fg_bg_delta))
149-
print(fg_bg_delta, fg_to_bg_dist, remaining_distance)
150-
print()
171+
151172
# Calculate all intersections, and direct compliments...
152173
# TODO: Actually compute 2d intersections of circle with bounds (rectangle) within valid color plane.
153174
# than pick nearest color...
154-
fg_shifted = (
155-
nearest_bg_point_on_plane + (remaining_distance / fg_to_bg_dist) * (fg_color - nearest_bg_point_on_plane)
156-
)
175+
fg_shifted = nearest_bg_point_on_plane + (remaining_distance / fg_to_bg_dist) * (fg_color - nearest_bg_point_on_plane),
176+
nearest_bg_point_on_plane + (remaining_distance / fg_to_bg_dist) * (fg_color - nearest_bg_point_on_plane)
157177

158178
l_bounds = (0, 1)
159179
ab_bounds = (-0.5, 0.5)
160-
161-
print(linear_rgb_to_srgb(oklab_to_linear_rgb(np.where(fg_to_bg_dist < remaining_distance, fg_shifted, fg_color)), as_int8))
162180
return linear_rgb_to_srgb(oklab_to_linear_rgb(np.where(fg_to_bg_dist < remaining_distance, fg_shifted, fg_color)), as_int8)
163181

164182

@@ -168,8 +186,7 @@ def __init__(self, widget: wx.Control, min_color_dist: float = 0.5, accented_alp
168186
self.foreground_color = widget.GetForegroundColour()
169187

170188
def apply_apca(fg, bg, desired_val):
171-
#return fg
172-
return wx.Colour(*contrastify_color(fg[:3], bg[:3], desired_val, True), 255)
189+
return wx.Colour(*fg[:3], 255)
173190

174191
def alpha_shift(color, salpha):
175192
return wx.Colour(*color[:3], int(color.Alpha() * salpha))

0 commit comments

Comments
 (0)