Inter-segment opening angles in a section
766446
def section_meander_angles(section):
    ''''''
    p = section.points
    return [mm.angle_3points(p[i - 1], p[i - 2], p[i])
            for i in range(2, len(p))]
1342847
function(oChild1, oChild2) {
			var oGeometry1 = DOMUtil.getGeometry(oChild1);
			var oGeometry2 = DOMUtil.getGeometry(oChild2);
			var oPosition1 = oGeometry1 && oGeometry1.position;
			var oPosition2 = oGeometry2 && oGeometry2.position;

			if (oPosition1 && oPosition2) {
				var iBottom1 = oPosition1.top + oGeometry1.size.height;
				var iBottom2 = oPosition2.top + oGeometry2.size.height;

				if (oPosition1.top < oPosition2.top) {
					if (iBottom1 >= iBottom2 && oPosition2.left < oPosition1.left) {
						/*  Example:
							            +--------------+
							+------+    |              |
							|  2   |    |       1      |
							+------+    |              |
							            +--------------+
							Despites 1st overlay's top is above 2nd element,
							the order should be switched, since 2nd element
							is shorter and is more to the left
						 */
						return 1;
					} else {
						return -1; // do not switch order
					}
				} else if (oPosition1.top === oPosition2.top) {
					if (oPosition1.left === oPosition2.left) {
						// Give priority to smaller block by height or width
						if (
							oGeometry1.size.height < oGeometry2.size.height
							|| oGeometry1.size.width < oGeometry2.size.width
						) {
							return -1;
						} else if (
							oGeometry1.size.height > oGeometry2.size.height
							|| oGeometry1.size.width > oGeometry2.size.width
						) {
							return 1;
						} else {
							return 0;
						}
					} else if (oPosition1.left < oPosition2.left) {
						return -1; // order is correct
					} else {
						return 1; // switch order
					}
				} else if (iBottom1 <= iBottom2 && oPosition2.left > oPosition1.left) { // if (oPosition1.top > oPosition2.top)
					/* see picture above, but switch 1 and 2 - order is correct */
					return -1;
				} else {
					/*  Example:
						            +--------------+
						+------+    |       2      |
						|  1   |    +--------------+
						|      |
						+------+

						Since 1st overlay's both top and bottom coordinates are
						bellow in dom, then top and bottom of 2nd, they should be switched
					 */
					return 1;
				}
			}
			return 0;
		}
1178497
protected void processIntersectionsSplitHorizontal()
    {
        boolean change;
        do
        {
            Vector<Separator> newsep = new Vector<Separator>(hsep.size());
            change = false;
            for (Separator hs : hsep)
            {
            	boolean split = false;
                for (Separator vs : vsep)
                {
                    if (hs.intersects(vs))
                    {
                        Separator nhs = hs.hsplit(vs);
                        newsep.add(hs);
                        if (nhs != null)
                            newsep.add(nhs);
                        split = true;
                        change = true;
                        break; //do not try other vertical seps
                    }
                }
                if (!split)
                	newsep.add(hs);
            }
            hsep = newsep;
        } while (change);
    }
744102
function(p) {

            if (!p) return false;

            var segments = this.segments;
            var otherSegments = p.segments;

            var numSegments = segments.length;
            if (otherSegments.length !== numSegments) return false; // if the two paths have different number of segments, they cannot be equal

            for (var i = 0; i < numSegments; i++) {

                var segment = segments[i];
                var otherSegment = otherSegments[i];

                // as soon as an inequality is found in segments, return false
                if ((segment.type !== otherSegment.type) || (!segment.equals(otherSegment))) return false;
            }

            // if no inequality found in segments, return true
            return true;
        }
22053
def associate_psds_to_multi_ifo_segments(opt, fd_segments, gwstrain, flen,
                                         delta_f, flow, ifos,
                                         dyn_range_factor=1., precision=None):
    
    for ifo in ifos:
        if gwstrain is not None:
            strain = gwstrain[ifo]
        else:
            strain = None

        if fd_segments is not None:
            segments = fd_segments[ifo]
        else:
            segments = None

        associate_psds_to_single_ifo_segments(opt, segments, strain, flen,
                delta_f, flow, ifo, dyn_range_factor=dyn_range_factor,
                precision=precision)
217453
def segments_overlapping(ab, cd):
    '''
    
    '''
    (a,b) = ab
    (c,d) = cd
    ss = [point_in_segment(ab, c), point_in_segment(ab, d),
          point_in_segment(cd, a), point_in_segment(cd, b)]
    return (~(points_close(a,b) | points_close(c,d)) & 
            ((np.sum(ss, axis=0) > 1) |
             (points_close(a,c) & points_close(b,d)) |
             (points_close(a,d) & points_close(b,c))))
754809
function (segment, point, i) {
		var smoothing = 1.5, // 1 means control points midway between points, 2 means 1/3 from the point, 3 is 1/4 etc
			denom = smoothing + 1,
			plotX = point.plotX,
			plotY = point.plotY,
			lastPoint = segment[i - 1],
			nextPoint = segment[i + 1],
			leftContX,
			leftContY,
			rightContX,
			rightContY,
			ret;

		// find control points
		if (i && i < segment.length - 1) {
			var lastX = lastPoint.plotX,
				lastY = lastPoint.plotY,
				nextX = nextPoint.plotX,
				nextY = nextPoint.plotY,
				correction;

			leftContX = (smoothing * plotX + lastX) / denom;
			leftContY = (smoothing * plotY + lastY) / denom;
			rightContX = (smoothing * plotX + nextX) / denom;
			rightContY = (smoothing * plotY + nextY) / denom;

			// have the two control points make a straight line through main point
			correction = ((rightContY - leftContY) * (rightContX - plotX)) /
				(rightContX - leftContX) + plotY - rightContY;

			leftContY += correction;
			rightContY += correction;

			// to prevent false extremes, check that control points are between
			// neighbouring points' y values
			if (leftContY > lastY && leftContY > plotY) {
				leftContY = mathMax(lastY, plotY);
				rightContY = 2 * plotY - leftContY; // mirror of left control point
			} else if (leftContY < lastY && leftContY < plotY) {
				leftContY = mathMin(lastY, plotY);
				rightContY = 2 * plotY - leftContY;
			}
			if (rightContY > nextY && rightContY > plotY) {
				rightContY = mathMax(nextY, plotY);
				leftContY = 2 * plotY - rightContY;
			} else if (rightContY < nextY && rightContY < plotY) {
				rightContY = mathMin(nextY, plotY);
				leftContY = 2 * plotY - rightContY;
			}

			// record for drawing in next point
			point.rightContX = rightContX;
			point.rightContY = rightContY;

		}

		// moveTo or lineTo
		if (!i) {
			ret = [M, plotX, plotY];
		} else { // curve from last point to this
			ret = [
				'C',
				lastPoint.rightContX || lastPoint.plotX,
				lastPoint.rightContY || lastPoint.plotY,
				leftContX || plotX,
				leftContY || plotY,
				plotX,
				plotY
			];
			lastPoint.rightContX = lastPoint.rightContY = null; // reset for updating series later
		}
		return ret;
	}
1206606
def _bend_angle_low(a, b, deriv):
    """"""
    result = _bend_cos_low(a, b, deriv)
    return _cos_to_angle(result, deriv)
95849
def _square_segment(radius, origin):
    '''
    '''
    return np.array(((origin[0] - radius, origin[1] - radius),
                     (origin[0] - radius, origin[1] + radius),
                     (origin[0] + radius, origin[1] + radius),
                     (origin[0] + radius, origin[1] - radius)))
778466
private void determineInsetsAndAlignment() {
        borderInsets = new Insets(0, 0, 0, 0);

        //  The insets will only be updated for the edge the component will be
        //  diplayed on.
        //
        //  The X, Y alignment of the component is controlled by both the edge
        //  and alignment parameters

        if (edge == Edge.TOP) {
            borderInsets.top = component.getPreferredSize().height + gap;
            component.setAlignmentX(alignment);
            component.setAlignmentY(0.0f);
        } else if (edge == Edge.BOTTOM) {
            borderInsets.bottom = component.getPreferredSize().height + gap;
            component.setAlignmentX(alignment);
            component.setAlignmentY(1.0f);
        } else if (edge == Edge.LEFT) {
            borderInsets.left = component.getPreferredSize().width + gap;
            component.setAlignmentX(0.0f);
            component.setAlignmentY(alignment);
        } else if (edge == Edge.RIGHT) {
            borderInsets.right = component.getPreferredSize().width + gap;
            component.setAlignmentX(1.0f);
            component.setAlignmentY(alignment);
        }

        if (adjustInsets) {
            adjustBorderInsets();
        }
    }
721333
def segment_meander_angles(neurites, neurite_type=NeuriteType.all):
    ''''''
    return list(chain.from_iterable(map_sections(
        sectionfunc.section_meander_angles, neurites, neurite_type)))
467196
def local_bifurcation_angles(neurites, neurite_type=NeuriteType.all):
    ''''''
    return map_sections(_bifurcationfunc.local_bifurcation_angle,
                        neurites,
                        neurite_type=neurite_type,
                        iterator_type=Tree.ibifurcation_point)
115373
public static function angle(
        Segment $a,
        Segment $b,
        Segment $c
    ): Degree {
        $a = $a->length();
        $b = $b->length();
        $c = $c->length();
        $longest = max($a, $b, $c);
        $opposites = (new Set(Number::class))
            ->add($a)
            ->add($b)
            ->add($c)
            ->remove($longest);
        $opposites = add(...$opposites);

        if ($longest->higherThan($opposites) && !$longest->equals($opposites)) {
            throw new SegmentsCannotBeJoined;
        }

        $cosAB = $a
            ->power(new Integer(2))
            ->add($b->power(new Integer(2)))
            ->subtract($c->power(new Integer(2)))
            ->divideBy(
                (new Integer(2))
                    ->multiplyBy($a)
                    ->multiplyBy($b)
            );

        return arcCosine($cosAB)->toDegree();
    }
970904
def _center(code, segment_dict):
    """"""
    while code in segment_dict:
        segment = segment_dict[code]
        yield segment
        code = segment.center
722251
def getSomaPos(self):
        ''' '''
        n3dsoma = 0
        r3dsoma = np.zeros(3)
        for sec in [sec for secName, sec in self.secs.items() if 'soma' in secName]:
            sec['hObj'].push()
            n3d = int(h.n3d())  # get number of n3d points in each section
            r3d = np.zeros((3, n3d))  # to hold locations of 3D morphology for the current section
            n3dsoma += n3d

            for i in range(n3d):
                r3dsoma[0] += h.x3d(i)
                r3dsoma[1] += h.y3d(i)
                r3dsoma[2] += h.z3d(i)

            h.pop_section() 
        
        r3dsoma /= n3dsoma

        return r3dsoma
505900
function positionRectangleInsideAnother(pos, a, b) {
    var aWidth = a.x2 - a.x1;
    var aHeight = a.y2 - a.y1;

    var bWidth = b.x2 - b.x1;
    var bHeight = b.y2 - b.y1;

    if (bHeight <= aHeight || bWidth <= aWidth) {
        return a;
    }

    var adjusted;
    switch (pos) {
        case "center":
            return {
                x1: a.x1 + (bWidth - aWidth)/2,
                x2: a.x2 + (bWidth - aWidth)/2,
                y1: a.y1 + (bHeight - aHeight)/2,
                y2: a.y2 + (bHeight - aHeight)/2
            };
        case "ne":
            return {
                x1: a.x1 + (bWidth - aWidth),
                x2: a.x2 + (bWidth - aWidth),
                y1: a.y1,
                y2: a.y2
            };
        case "se":
            return {
                x1: a.x1 + (bWidth - aWidth),
                x2: a.x2 + (bWidth - aWidth),
                y1: a.y1 + (bHeight - aHeight),
                y2: a.y2 + (bHeight - aHeight)
            };
        case "sw":
            return {
                x1: a.x1,
                x2: a.x2,
                y1: a.y1 + (bHeight - aHeight),
                y2: a.y2 + (bHeight - aHeight)
            };
        case "nw":
        default:
            return a;
    }

    return {}
}
207526
def segment_alignment
      # special cases: 12 for x86/64/PPC/PP64, 14 for ARM/ARM64
      return 12 if %i[i386 x86_64 ppc ppc64].include?(cputype)
      return 14 if %i[arm arm64].include?(cputype)

      cur_align = Sections::MAX_SECT_ALIGN

      segments.each do |segment|
        if filetype == :object
          # start with the smallest alignment, and work our way up
          align = magic32? ? 2 : 3
          segment.sections.each do |section|
            align = section.align unless section.align <= align
          end
        else
          align = segment.guess_align
        end
        cur_align = align if align < cur_align
      end

      cur_align
    end