region Helper Methods
480326
private void bindViews() {
        recyclerView = (RecyclerView) findViewById(R.id.rv);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
    }
639738
function clickRegion( e ) {
	
	let pos 	= {
		x : e.clientX,
		y : e.clientY
	},
	region 		= '',
	dividant 	= 4,
	right  		= window.innerWidth - (window.innerWidth / dividant),
	left   		= (window.innerWidth / dividant),
	top    		= (window.innerHeight / dividant),
	bottom 		= window.innerHeight - (window.innerHeight / dividant);

	if( pos.y <= top ) { region = 'top'; }
	else if(  pos.y >= bottom ) { region = 'bottom'; }

	if( pos.x <= left ) { region = 'left'; }
	else if(  pos.x >= right ) { region = 'right'; }

	return region;
}
966047
@Override
    public void areaSelected(Area area)
    {
        //show the separator list
        if (area instanceof AreaImpl)
        {
            SeparatorSet sset = Config.createSeparators((AreaImpl) area);
            DefaultListModel<Separator> ml = new DefaultListModel<Separator>();
            for (Separator sep : sset.getHorizontal())
                ml.addElement(sep);
            for (Separator sep : sset.getVertical())
                ml.addElement(sep);
            for (Separator sep : sset.getBoxsep())
                ml.addElement(sep);
            sepList.setModel(ml);
        }
        else
        {
            //not a grouping area -- no separators
            sepList.setModel(new DefaultListModel<Separator>());
        }
    }
128230
def focusedWindow(cls):
        
        x, y, w, h = PlatformManager.getWindowRect(PlatformManager.getForegroundWindow())
        return Region(x, y, w, h)
233173
protected void recursiveSortLines(AreaImpl root)
    {
        sortChildLines(root);
        for (int i = 0; i < root.getChildCount(); i++)
            recursiveSortLines((AreaImpl) root.getChildAt(i));
    }
    
    /**
     * Goes through the grid of areas and sorts the adjacent visual areas that are not
     * separated by anything
     */
    protected void sortChildLines(AreaImpl root)
    {
        if (root.getChildCount() > 1)
        {
            List<Area> src = new Vector<Area>(root.getChildren());
            List<Area> dest = new Vector<Area>(src.size());
            while (!src.isEmpty())
            {
                final AreaImpl seed = (AreaImpl) src.get(0);
                List<Area> line = findAreasOnLine(root, seed, src);
                dest.addAll(line);
                src.removeAll(line);
            }
            
            root.removeAllChildren();
            root.appendChildren(dest);
        }
    }

    private List<Area> findAreasOnLine(AreaImpl parent, AreaImpl area, List<Area> candidates)
    {
        Vector<Area> ret = new Vector<Area>();
        ret.add(area);
        
        final int nx1 = area.getGridPosition().getX1();
        final int ny1 = area.getGridPosition().getY1();
        final int nx2 = area.getGridPosition().getX2();
        final int ny2 = area.getGridPosition().getY2();
        final AreaTopology t = parent.getTopology();
        
        //try to expand to the right
        int dist = 1;
        while (nx2 + dist < t.getTopologyWidth())
        {
            //try to find some node at the right in the given distance
            for (int y = ny1; y <= ny2; y++)
            {
                AreaImpl neigh = (AreaImpl) t.findAreaAt(nx2 + dist, y);
                if (neigh != null && candidates.contains(neigh)) //something found
                {
                    //the maximal Y difference to consider other areas to be on the same line
                    int threshold = (Math.min(area.getHeight(), neigh.getHeight()) / 2);
                    if (threshold < 0) threshold = 0;
                    //check if the nodes could be on the same line
                    if (AreaUtils.isOnSameLine(area, neigh, threshold))
                    {
                        ret.add(neigh);
                        break;
                    }
                }
            }
            dist++;
        }
        //try to expand to the left
        dist = 1;
        while (nx1 - dist >= 0)
        {
            //try to find some node at the right in the given distance
            for (int y = ny1; y <= ny2; y++)
            {
                AreaImpl neigh = (AreaImpl) t.findAreaAt(nx1 - dist, y);
                if (neigh != null && candidates.contains(neigh)) //something found
                {
                    //the maximal Y difference to consider other areas to be on the same line
                    int threshold = (Math.min(area.getHeight(), neigh.getHeight()) / 2);
                    if (threshold < 0) threshold = 0;
                    //check if the nodes could be on the same line
                    if (AreaUtils.isOnSameLine(area, neigh, threshold))
                    {
                        ret.insertElementAt(neigh, 0);
                        break;
                    }
                }
            }
            dist++;
        }
            
        return ret;
    }
    
}
860394
public void readRegionToBuff(int off, int len, byte[] outBuff) {
		assert off >= 0;
		assert len > 0;
		assert outBuff != null;
		assert outBuff.length >= len;
		assert buffer.limit() >= off + len;

		buffer.position(off);
		buffer.get(outBuff, 0, len);
	}
1349045
public void setRegions(java.util.Collection<Region> regions) {
        if (regions == null) {
            this.regions = null;
            return;
        }

        this.regions = new java.util.ArrayList<Region>(regions);
    }
1121189
def iter_regions(self):
        
        # TODO: Implement BoundingBox
        # TODO: Implement sort order
        for x,z in self.regionfiles.keys():
            close_after_use = False
            if (x,z) in self.regions:
                regionfile = self.regions[(x,z)]
            else:
                # It is not yet cached.
                # Get file, but do not cache later.
                regionfile = region.RegionFile(self.regionfiles[(x,z)], chunkclass = self.chunkclass)
                regionfile.loc = Location(x=x,z=z)
                close_after_use = True
            try:
                yield regionfile
            finally:
                if close_after_use:
                    regionfile.close()
798545
protected void selectMerge( int pruneId , FastQueue<float[]> regionColor ) {
		// Grab information on the region which is being pruned
		Node n = pruneGraph.get(pruneId);
		float[] targetColor = regionColor.get(n.segment);

		// segment ID and distance away from the most similar neighbor
		int bestId = -1;
		float bestDistance = Float.MAX_VALUE;

		// Examine all the segments it is connected to to see which one it is most similar too
		for( int i = 0; i < n.edges.size; i++ ) {
			int segment = n.edges.get(i);
			float[] neighborColor = regionColor.get(segment);
			float d = SegmentMeanShiftSearch.distanceSq(targetColor, neighborColor);

			if( d < bestDistance ) {
				bestDistance = d;
				bestId = segment;
			}
		}

		if( bestId == -1 )
			throw new RuntimeException("No neighbors?  Something went really wrong.");

		markMerge(n.segment, bestId);
	}
1056362
def region_from_segment(image, segment):
    """"""
    x, y, w, h = segment
    return image[y:y + h, x:x + w]
425669
protected void learnAmbiguousNegative(Rectangle2D_F64 targetRegion) {

		TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);

		if( detection.isSuccess() ) {
			TldRegion best = detection.getBest();

			// see if it found the correct solution
			double overlap = helper.computeOverlap(best.rect,targetRegion_I32);
			if( overlap <= config.overlapLower ) {
				template.addDescriptor(false,best.rect);
//				fern.learnFernNoise(false, best.rect );
			}

			// mark all ambiguous regions as bad
			List<ImageRectangle> ambiguous = detection.getAmbiguousRegions();
			for( ImageRectangle r : ambiguous ) {
				overlap = helper.computeOverlap(r,targetRegion_I32);
				if( overlap <= config.overlapLower ) {
					fern.learnFernNoise(false, r );
					template.addDescriptor(false,r);
				}
			}
		}
	}
222705
public Region region (final float rx, final float ry, final float rwidth, final float rheight) {
    final Image image = this;
    return new Region() {
      private Tile tile;
      @Override public boolean isLoaded () { return image.isLoaded(); }
      @Override public Tile tile () {
        if (tile == null) tile = image.texture().tile(rx, ry, rwidth, rheight);
        return tile;
      }
      @Override public RFuture<Tile> tileAsync () {
        return image.state.map(new Function<Image,Tile>() {
          public Tile apply (Image image) { return tile(); }
        });
      }

      @Override public float width () { return rwidth; }
      @Override public float height () { return rheight; }

      @Override public void draw (Object ctx, float x, float y, float width, float height) {
        image.draw(ctx, x, y, width, height, rx, ry, rwidth, rheight);
      }
      @Override public void draw (Object ctx, float dx, float dy, float dw, float dh,
                                  float sx, float sy, float sw, float sh) {
        image.draw(ctx, dx, dy, dw, dh, rx+sx, ry+sy, sw, sh);
      }
    };
  }
751536
private Region find(Region x) {
    Region current = this.root;
    while (current != NULL_NODE) {
      long res = x.orderRelativeTo(current);
      if (res < 0) {
        current = current.left;
      } else if (res > 0) {
        current = current.right;
      } else {
        return current;
      }
    }
    return null;
  }
148601
def render_region(widget=None, request=None, view=None,
                  page=None, region=None):
    

    # change the request
    if not isinstance(request, dict):
        request.query_string = None
        request.method = "GET"

    if not hasattr(request, '_feincms_extra_context'):
        request._feincms_extra_context = {}

    leonardo_page = widget.parent if widget else page
    render_region = widget.region if widget else region

    # call processors
    for fn in reversed(list(leonardo_page.request_processors.values())):
        try:
            r = fn(leonardo_page, request)
        except:
            pass

    contents = {}

    for content in leonardo_page.content.all_of_type(tuple(
            leonardo_page._feincms_content_types_with_process)):

        try:
            r = content.process(request, view=view)
        except:
            pass
        else:
            # this is HttpResponse object or string
            if not isinstance(r, six.string_types):
                r.render()
                contents[content.fe_identifier] = getattr(r, 'content', r)
            else:
                contents[content.fe_identifier] = r

    from leonardo.templatetags.leonardo_tags import _render_content

    region_content = ''.join(
        contents[content.fe_identifier] if content.fe_identifier in contents else _render_content(
            content, request=request, context={})
        for content in getattr(leonardo_page.content, render_region))

    return region_content
1109667
def expectRegion(self, filename, x, y, maxrms=0):
        
        log.debug('expectRegion %s (%s, %s)', filename, x, y)
        return self._expectFramebuffer(filename, x, y, maxrms)
399316
async def regions(self, *args, **kwargs):
        

        return await self._makeApiCall(self.funcinfo["regions"], *args, **kwargs)
557705
function getActiveRegionTypeCode(item) {
  // We always put the region first, and at most one is active.
  var activeRegions = item._concepts[0].activeItems;
  if (activeRegions.length === 1) {
    return activeRegions[0].code;
  }
}