小编Amy*_*ose的帖子

遍历同心圆中的每个像素

我试图遍历每个像素坐标,从 (0, 0) 开始,以便在它们不重叠的最近偏移处融合两个像素化形状。

到现在为止,我一直在使用同心正方形,这确实很容易做到,但最终可能会将嫁接图像放置得更远。然后我实现了 Bresenham 圆算法如下:

def generate_offsets(maxRadius : int):
    """Generate x and y coordinates in concentric circles around the origin
    Uses Bresenham's Circle Drawing Algorithm
    """
    
    for radius in range(maxRadius):
        x = 0
        y = radius
        d = 3 - (2 * radius)
        while x < y:
        
            yield x, y
            yield y, x
            yield y, -x
            yield x, -y
            yield -x, -y
            yield -y, -x
            yield -y, x
            yield -x, y
            
            if d < 0:
                d += (4 …
Run Code Online (Sandbox Code Playgroud)

python geometry pixel bresenham

5
推荐指数
1
解决办法
156
查看次数

UnkeyedEncodingContainer 和 KeyedEncodingContainerProtocol 中的 superEncoder 有何用途?

我很抱歉问这样一个基本问题,但我无法在任何地方找到答案:

为了制作一个Encoder,您必须定义不同类型的容器:

  • SingleValueEncodingContainer
  • UnkeyedEncodingContainer
  • KeyedEncodingContainerProtocol是的,命名规范很奇怪

最后两个必须都包含一个名为的方法superEncoder,但是我无法在任何地方找到它应该做什么。这个问题有一个实现它的答案,但没有解释它,本次演讲只是顺便提到了它。

它应该做什么,有什么用?

encoding swift

4
推荐指数
1
解决办法
683
查看次数

类型“()”不能符合View(除非它肯定是一个View,这次没有恶作剧)

我知道这是一个奇怪的标题,但有很多帖子具有相似的标题和完全不同的问题。大多数人View在他们的视图中编写除代码之外的其他内容,而我没有这样做(据我所知)。

我正在尝试Picker与其他BinaryInteger类型兼容,因为它不适用于除 之外的任何类型Int,并且我在使预览正常工作时遇到了一些麻烦。这是代码:

import SwiftUI

struct CompatibilityPicker<Label, SelectionValue, Content> : View where Label : StringProtocol, SelectionValue : BinaryInteger, Content : View {
    
    var content : () -> Content
    var label : Label
    
    @Binding private var _selection : SelectionValue
    
    private var selection: Binding<Int> { Binding<Int>(
        get: {
            Int(_selection)
        },
        set: {
            self._selection = SelectionValue($0)
        })
    }
    
    init(_ label : Label, selection : SelectionValue, content : @escaping () -> Content) {
        self.label = label …
Run Code Online (Sandbox Code Playgroud)

view picker swift swiftui

2
推荐指数
1
解决办法
2144
查看次数

从 Ocaml 中的嵌套条件中删除重复的语句

作为课堂练习,我们应该根据年龄和性别计算夜总会人员的入场费。25 岁以下可享受 20% 折扣,女性/NB 可享受 50% 折扣,乘数叠加叠加。

虽然我的代码可以工作,但它会重复性别检查两次,这是一种糟糕的形式,可能会在更复杂的应用程序中导致问题。怎样才能避免重复呢?

(* OCaml Version *)
let entry_price age gender =
    if age < 18 
    then (failwith "Must be over 18 to enter")
    else let price = 12.0 in
      if age <= 25
      then let price = (price *. 0.8) in
        if gender == 'f' || gender == 'x'
        then (price *. 0.5)
        else prix
      else if gender == 'f' || gender == 'x'
        then (price *. 0.5)
        else price;;

Run Code Online (Sandbox Code Playgroud)

这是一个不会重复的 Python …

ocaml

0
推荐指数
1
解决办法
83
查看次数

标签 统计

swift ×2

bresenham ×1

encoding ×1

geometry ×1

ocaml ×1

picker ×1

pixel ×1

python ×1

swiftui ×1

view ×1