// toggleShape adds or removes the given shapeID from the set of IDs it is tracking.
489306
func (t *tracker) toggleShape(shapeID int32) {
	// Most shapeIDs slices are small, so special case the common steps.

	// If there is nothing here, add it.
	if len(t.shapeIDs) == 0 {
		t.shapeIDs = append(t.shapeIDs, shapeID)
		return
	}

	// If it's the first element, drop it from the slice.
	if t.shapeIDs[0] == shapeID {
		t.shapeIDs = t.shapeIDs[1:]
		return
	}

	for i, s := range t.shapeIDs {
		if s < shapeID {
			continue
		}

		// If it's in the set, cut it out.
		if s == shapeID {
			copy(t.shapeIDs[i:], t.shapeIDs[i+1:]) // overwrite the ith element
			t.shapeIDs = t.shapeIDs[:len(t.shapeIDs)-1]
			return
		}

		// We've got to a point in the slice where we should be inserted.
		// (the given shapeID is now less than the current positions id.)
		t.shapeIDs = append(t.shapeIDs[0:i],
			append([]int32{shapeID}, t.shapeIDs[i:len(t.shapeIDs)]...)...)
		return
	}

	// We got to the end and didn't find it, so add it to the list.
	t.shapeIDs = append(t.shapeIDs, shapeID)
}
159432
func Flatten(list cty.Value) (cty.Value, error) {
	return FlattenFunc.Call([]cty.Value{list})
}
409308
func (p *Pattern) geoTriangles() {
	scale := utils.HexVal(p.Hash, 0, 1)
	sideLength := utils.Map(scale, 0, 15, 15, 80)
	triangleHeight := sideLength / 2 * math.Sqrt(3)
	triangle := shapes.BuildTriangle(sideLength, triangleHeight)

	p.Svg.SetHeight(int(triangleHeight * 6))
	p.Svg.SetWidth(int(sideLength * 3))

	i := 0
	for y := 0; y <= 5; y++ {
		for x := 0; x <= 5; x++ {

			val := utils.HexVal(p.Hash, i, 1)
			opacity := utils.Opacity(val)
			fill := utils.FillColor(val)

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["fill-opacity"] = opacity
			styles["stroke"] = utils.StrokeColor
			styles["stroke-opacity"] = utils.StrokeOpacity

			var rotation int
			if y%2 == 0 {
				if x%2 == 0 {
					rotation = 180
				}
			} else {
				if x%2 != 0 {
					rotation = 180
				}
			}

			style := make(map[string]interface{})

			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", float64(x)*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", 6*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2)
				p.Svg.Polyline(triangle, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
1148926
func newClippedShape(id int32, numEdges int) *clippedShape {
	return &clippedShape{
		shapeID: id,
		edges:   make([]int, numEdges),
	}
}
916650
func (r *ChangeCauseRecorder) MakeRecordMergePatch(obj runtime.Object) ([]byte, error) {
	// copy so we don't mess with the original
	objCopy := obj.DeepCopyObject()
	if err := r.Record(objCopy); err != nil {
		return nil, err
	}

	oldData, err := json.Marshal(obj)
	if err != nil {
		return nil, err
	}
	newData, err := json.Marshal(objCopy)
	if err != nil {
		return nil, err
	}

	return jsonpatch.CreateMergePatch(oldData, newData)
}
906989
func (brq *blockRetrievalQueue) TogglePrefetcher(enable bool,
	testSyncCh <-chan struct{}, testDoneCh chan<- struct{}) <-chan struct{} {
	// We must hold this lock for the whole function so that multiple calls to
	// this function doesn't leak prefetchers.
	brq.prefetchMtx.Lock()
	defer brq.prefetchMtx.Unlock()
	// Allow the caller to block on the current shutdown.
	ch := brq.prefetcher.Shutdown()
	if enable {
		brq.prefetcher = newBlockPrefetcher(
			brq, brq.config, testSyncCh, testDoneCh)
	}
	return ch
}
29929
func (m MorphSlice) WriteTo(w io.Writer) (n int64, err error) {
	l := int64(len(m))
	if err = binary.Write(w, binary.LittleEndian, l); err != nil {
		return
	}
	n += int64(binary.Size(l))
	for i := range m {
		if err = binary.Write(w, binary.LittleEndian, m[i].LeftID); err != nil {
			return n, err
		}
		n += int64(binary.Size(m[i].LeftID))
		if err = binary.Write(w, binary.LittleEndian, m[i].RightID); err != nil {
			return
		}
		n += int64(binary.Size(m[i].RightID))
		if err = binary.Write(w, binary.LittleEndian, m[i].Weight); err != nil {
			return
		}
		n += int64(binary.Size(m[i].Weight))
	}
	return
}
706020
func (s *ShapeIndex) Remove(shape Shape) {
	// The index updates itself lazily because it is much more efficient to
	// process additions and removals in batches.
	id := s.idForShape(shape)

	// If the shape wasn't found, it's already been removed or was not in the index.
	if s.shapes[id] == nil {
		return
	}

	// Remove the shape from the shapes map.
	delete(s.shapes, id)

	// We are removing a shape that has not yet been added to the index,
	// so there is nothing else to do.
	if id >= s.pendingAdditionsPos {
		return
	}

	numEdges := shape.NumEdges()
	removed := &removedShape{
		shapeID:               id,
		hasInterior:           shape.Dimension() == 2,
		containsTrackerOrigin: shape.ReferencePoint().Contained,
		edges:                 make([]Edge, numEdges),
	}

	for e := 0; e < numEdges; e++ {
		removed.edges[e] = shape.Edge(e)
	}

	s.pendingRemovals = append(s.pendingRemovals, removed)
	atomic.StoreInt32(&s.status, stale)
}
334057
func (t *configTree) Flatten() (*Config, error) {
	// No children is easy: we're already merged!
	if len(t.Children) == 0 {
		return t.Config, nil
	}

	// Depth-first, merge all the children first.
	childConfigs := make([]*Config, len(t.Children))
	for i, ct := range t.Children {
		c, err := ct.Flatten()
		if err != nil {
			return nil, err
		}

		childConfigs[i] = c
	}

	// Merge all the children in order
	config := childConfigs[0]
	childConfigs = childConfigs[1:]
	for _, config2 := range childConfigs {
		var err error
		config, err = Merge(config, config2)
		if err != nil {
			return nil, err
		}
	}

	// Merge the final merged child config with our own
	return Merge(config, t.Config)
}
973237
func MouseToggle(togKey string, args ...interface{}) {
	var button C.MMMouseButton = C.LEFT_BUTTON

	if len(args) > 0 {
		button = CheckMouse(args[0].(string))
	}

	down := C.CString(togKey)
	C.mouse_toggle(down, button)

	C.free(unsafe.Pointer(down))
}
403179
func defaultShapeIsEmpty(s Shape) bool {
	return s.NumEdges() == 0 && (s.Dimension() != 2 || s.NumChains() == 0)
}
960167
func (pattern *MeshPattern) MoveTo(x, y float64) {
	C.cairo_mesh_pattern_move_to(pattern.Ptr, C.double(x), C.double(y))
	if err := pattern.status(); err != nil {
		panic(err)
	}
}
1198084
func (light *Light) Toggle() error {
	if light.State.On {
		return light.Off()
	}
	return light.On()
}
893538
func (r *referenceResolver) resolveShape(shape *Shape) {
	r.resolveReference(&shape.MemberRef)
	r.resolveReference(&shape.KeyRef)
	r.resolveReference(&shape.ValueRef)
	for _, m := range shape.MemberRefs {
		r.resolveReference(m)
	}
}
22836
func (pattern *MeshPattern) CurveTo(x1, y1, x2, y2, x3, y3 float64) {
	C.cairo_mesh_pattern_curve_to(pattern.Ptr, C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(x3), C.double(y3))
	if err := pattern.status(); err != nil {
		panic(err)
	}
}
933707
func (w *Window) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles {
	return w.canvas.MakeTriangles(t)
}
919302
func (d *DNSServer) toggleRecursorHandlerFromConfig(cfg *dnsConfig) {
	shouldEnable := len(cfg.Recursors) > 0

	if shouldEnable && atomic.CompareAndSwapUint32(&d.recursorEnabled, 0, 1) {
		d.mux.HandleFunc(".", d.handleRecurse)
		d.logger.Println("[DEBUG] dns: recursor enabled")
		return
	}

	if !shouldEnable && atomic.CompareAndSwapUint32(&d.recursorEnabled, 1, 0) {
		d.mux.HandleRemove(".")
		d.logger.Println("[DEBUG] dns: recursor disabled")
		return
	}
}