<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[question: contours and components inside some rect]]></title><description><![CDATA[<p dir="auto">Small scripting question. (Hopefully this heavy rain of the questions will end up at some point)</p>
<p dir="auto">What is the easiest way to check if some contour or component in the glyph is inside some abstract rectangle?</p>
<p dir="auto">I have coordinates and size of the rectangle. Now I would like to check out if the objects shapes are inside it.</p>
<p dir="auto">Determining if points are inside the rect is easy. But when it comes to components and contours: something that have lines and curves is really hard.<br />
I've been trying to creating the function, that would take the contour or component as an argument, and return True or False value. (True if at least part of the shape is inside the rectangle). I've been trying to do it with the booleanOperators and I failed.</p>
<p dir="auto">Any help?</p>
<p dir="auto">By the way, I'm thinking that it could be a bug:</p>
<pre><code>from mojo.tools import union
g = CurrentGlyph()
union(g, g[0], g[1], roundCoordinates=None)
</code></pre>
<p dir="auto">gives</p>
<pre><code class="language-console">Traceback (most recent call last):
  File "&lt;untitled&gt;", line 3, in &lt;module&gt;
  File "/Applications/RoboFont3.app/Contents/Resources/lib/python3.6/mojo/tools.py", line 84, in union
  File "/Applications/RoboFont3.app/Contents/Resources/lib/python3.6/mojo/tools.py", line 84, in &lt;listcomp&gt;
  File "/Applications/RoboFont3.app/Contents/Resources/lib/python3.6/fontParts/base/base.py", line 255, in naked
  File "/Applications/RoboFont3.app/Contents/Resources/lib/python3.6/fontParts/base/base.py", line 232, in raiseNotImplementedError
NotImplementedError: The RSegment subclass does not implement this method.
</code></pre>
]]></description><link>https://forum.robofont.com/topic/581/question-contours-and-components-inside-some-rect</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 12:30:42 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/581.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Feb 2019 23:27:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to question: contours and components inside some rect on Thu, 25 Apr 2019 21:08:45 GMT]]></title><description><![CDATA[<p dir="auto">Small scripting question. (Hopefully this heavy rain of the questions will end up at some point)</p>
<p dir="auto">What is the easiest way to check if some contour or component in the glyph is inside some abstract rectangle?</p>
<p dir="auto">I have coordinates and size of the rectangle. Now I would like to check out if the objects shapes are inside it.</p>
<p dir="auto">Determining if points are inside the rect is easy. But when it comes to components and contours: something that have lines and curves is really hard.<br />
I've been trying to creating the function, that would take the contour or component as an argument, and return True or False value. (True if at least part of the shape is inside the rectangle). I've been trying to do it with the booleanOperators and I failed.</p>
<p dir="auto">Any help?</p>
<p dir="auto">By the way, I'm thinking that it could be a bug:</p>
<pre><code>from mojo.tools import union
g = CurrentGlyph()
union(g, g[0], g[1], roundCoordinates=None)
</code></pre>
<p dir="auto">gives</p>
<pre><code class="language-console">Traceback (most recent call last):
  File "&lt;untitled&gt;", line 3, in &lt;module&gt;
  File "/Applications/RoboFont3.app/Contents/Resources/lib/python3.6/mojo/tools.py", line 84, in union
  File "/Applications/RoboFont3.app/Contents/Resources/lib/python3.6/mojo/tools.py", line 84, in &lt;listcomp&gt;
  File "/Applications/RoboFont3.app/Contents/Resources/lib/python3.6/fontParts/base/base.py", line 255, in naked
  File "/Applications/RoboFont3.app/Contents/Resources/lib/python3.6/fontParts/base/base.py", line 232, in raiseNotImplementedError
NotImplementedError: The RSegment subclass does not implement this method.
</code></pre>
]]></description><link>https://forum.robofont.com/post/2020</link><guid isPermaLink="true">https://forum.robofont.com/post/2020</guid><dc:creator><![CDATA[RafaŁ Buchner]]></dc:creator><pubDate>Thu, 25 Apr 2019 21:08:45 GMT</pubDate></item><item><title><![CDATA[Reply to question: contours and components inside some rect on Fri, 08 Feb 2019 01:23:21 GMT]]></title><description><![CDATA[<p dir="auto">you can use the bounds of the contours or components to check if they overlap with the rectangle:</p>
<pre><code class="language-python">def overlaps(contourOrComponent, box):

    left, bottom, right, top = contourOrComponent.bounds
    rectLeft, rectBottom, rectRight, rectTop = box

    xOverlap = right &gt; rectLeft and left &lt; rectRight
    yOverlap = top &gt; rectBottom and bottom &lt; rectTop

    if xOverlap and yOverlap:
        return True
    else:
        return False

x, y, w, h = 118, 246, 104, 402
box = x, y, x+w, y+h

g = CurrentGlyph()

for c in g.contours:
    print(overlaps(c, box), c)

for c in g.components:
    print(overlaps(c, box), c)
</code></pre>
]]></description><link>https://forum.robofont.com/post/2022</link><guid isPermaLink="true">https://forum.robofont.com/post/2022</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Fri, 08 Feb 2019 01:23:21 GMT</pubDate></item><item><title><![CDATA[Reply to question: contours and components inside some rect on Fri, 08 Feb 2019 01:45:10 GMT]]></title><description><![CDATA[<p dir="auto">regarding <code>union</code>: you need to use <a href="http://robofont.com/documentation/building-tools/api/mojo/mojo-tools/#mojo.tools.union" rel="nofollow">a glyph or a list of contours</a>:</p>
<pre><code class="language-python">from mojo.tools import union
g = CurrentGlyph()
union(g, [g[0&rsqb;&rsqb;, [g[1&rsqb;&rsqb;, roundCoordinates=None)
</code></pre>
]]></description><link>https://forum.robofont.com/post/2023</link><guid isPermaLink="true">https://forum.robofont.com/post/2023</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Fri, 08 Feb 2019 01:45:10 GMT</pubDate></item><item><title><![CDATA[Reply to question: contours and components inside some rect on Fri, 15 Feb 2019 10:44:28 GMT]]></title><description><![CDATA[<p dir="auto">Two circular components could have overlapping bounds but have no visual overlap. The only option to check is to perform a remove overlap and look for changes. This means for components you have to decompose first.</p>
<p dir="auto">good luck!</p>
]]></description><link>https://forum.robofont.com/post/2025</link><guid isPermaLink="true">https://forum.robofont.com/post/2025</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Fri, 15 Feb 2019 10:44:28 GMT</pubDate></item><item><title><![CDATA[Reply to question: contours and components inside some rect on Fri, 08 Feb 2019 12:46:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/1">@frederik</a> true! but in this case we know that the frame is a rectangle – so checking the bounds works too. here’s a proof:</p>
<p dir="auto"><img src="/assets/uploads/files/1549629993682-overlap-proof.png" alt="overlap-proof.png" class="img-responsive img-markdown" /></p>
<pre><code class="language-python">g = CurrentGlyph()

x, y, w, h = 206, -218, 358, 392
box = x, y, x+w, y+h

translate(230, 270)

for contour in g.contours:
    color = (0, 1, 0) if overlaps(contour, box) else (1, 0, 0)
    fill(*color)
    B = BezierPath()
    contour.draw(B)
    drawPath(B)

stroke(0)
strokeWidth(10)
fill(None)
drawGlyph(g)

stroke(0, 0, 1)
rect(x, y, w, h)
</code></pre>
]]></description><link>https://forum.robofont.com/post/2027</link><guid isPermaLink="true">https://forum.robofont.com/post/2027</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Fri, 08 Feb 2019 12:46:38 GMT</pubDate></item><item><title><![CDATA[Reply to question: contours and components inside some rect on Fri, 15 Feb 2019 10:45:36 GMT]]></title><description><![CDATA[<p dir="auto">oke, idd much simpler :)</p>
<p dir="auto">also take a look at <a href="https://github.com/fonttools/fonttools/blob/master/Lib/fontTools/misc/arrayTools.py#L84" rel="nofollow">fontTools arrayTools</a>:  <code>sectRect</code>, <code>pointsInRect</code>, <code>pointInRect</code></p>
]]></description><link>https://forum.robofont.com/post/2028</link><guid isPermaLink="true">https://forum.robofont.com/post/2028</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Fri, 15 Feb 2019 10:45:36 GMT</pubDate></item><item><title><![CDATA[Reply to question: contours and components inside some rect on Fri, 08 Feb 2019 14:09:07 GMT]]></title><description><![CDATA[<p dir="auto">Great! Thanks for the help!</p>
]]></description><link>https://forum.robofont.com/post/2030</link><guid isPermaLink="true">https://forum.robofont.com/post/2030</guid><dc:creator><![CDATA[RafaŁ Buchner]]></dc:creator><pubDate>Fri, 08 Feb 2019 14:09:07 GMT</pubDate></item><item><title><![CDATA[Reply to question: contours and components inside some rect on Fri, 08 Feb 2019 14:12:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/22">@gferreira</a> Hmm, I think it doesn't need to be true (Let's say that we have the shape of the glyph "C". The rect is inside of the letter: then it doesn't work)</p>
]]></description><link>https://forum.robofont.com/post/2031</link><guid isPermaLink="true">https://forum.robofont.com/post/2031</guid><dc:creator><![CDATA[RafaŁ Buchner]]></dc:creator><pubDate>Fri, 08 Feb 2019 14:12:17 GMT</pubDate></item><item><title><![CDATA[Reply to question: contours and components inside some rect on Fri, 08 Feb 2019 14:23:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/207">@RafaŁ-Buchner</a> you’re right :) better to use the boolean glyph method then.</p>
<p dir="auto"><img src="/assets/uploads/files/1549635762344-overlap-proof-failed.png" alt="overlap-proof-failed.png" class="img-responsive img-markdown" /></p>
]]></description><link>https://forum.robofont.com/post/2032</link><guid isPermaLink="true">https://forum.robofont.com/post/2032</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Fri, 08 Feb 2019 14:23:14 GMT</pubDate></item></channel></rss>